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-AzTrafficManagerProfilesuccessfully in devops, you need to use theAzure PowerShell taskand authenticated with theAzure Resource Manager service connection.Please refer to the steps below.
1.Create an
Azure PowerShell task, inAzure subscription->Available Azure subscriptions-> select the subscription you want to runGet-AzTrafficManagerProfileagainst.2.Then click the
Authorizebutton, it will create anAzure Resource Manager service connectionautomatically 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 administratorin the subscription, otherwise you have no permission to do this successfully.3.Then in the
Inline Script, just useGet-AzTrafficManagerProfiledirectly, no need to login manually, because it will login with the service connection automatically.4.Test the task, it works fine.