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.
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.
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.
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.
4.Test the task, it works fine.