Search code examples
azureazure-traffic-manager

Get-AzTrafficManagerProfile command is not running from inside the pipeline


I need to update the traffic manager profile in the pipeline to switch resources, when I run the command Get-AzTrafficManagerProfile in my local az cli with me logged-in it runs with no issues, but when I ran it as a task part of the Azure pipeline it threw the bellow error:

Get-AzTrafficManagerProfile : No account found in the context. Please login using Connect-AzAccount.

also tried to call Connect-AzAccount from inside the pipeline and it didn't work.


Solution

  • To run the command Get-AzTrafficManagerProfile successfully in devops, you need to use the Azure PowerShell task and authenticated with the Azure Resource Manager service connection.

    Please refer to the steps below.

    1.Create an Azure PowerShell task, in Azure subscription -> Available Azure subscriptions -> select the subscription you want to run Get-AzTrafficManagerProfile against.

    enter image description here

    2.Then click the Authorize button, it will create an Azure Resource Manager service connection automatically for you and assign a Contributor RBAC role at the subscription scope.

    Note: Make sure your user account logged in devops is the Owner/User Access administrator in the subscription, otherwise you have no permission to do this successfully.

    enter image description here

    3.Then in the Inline Script, just use Get-AzTrafficManagerProfile directly, no need to login manually, because it will login with the service connection automatically.

    enter image description here

    4.Test the task, it works fine.

    enter image description here