Reputation: 123
I have a release pipeline which is calling a PowerShell script and it is having 'Select-AzureSubscription' statement (In a loop I have to assign different subscriptions as current and do some process). When it runs, I am getting the below error as I have not added 'Add-AzureAccount'.
Select-AzureSubscription : The subscription name doesn't exist.
Is there any way to authenticate or execute Add-AzureAccount using the Pipeline access token.
Code:-
Select-AzureSubscription -SubscriptionName $Subscription -Current
CloudServices = Get-AzureService | select ServiceName
Upvotes: 1
Views: 704
Reputation: 42063
You could try the steps below(I could not test it for you as I don't have a user account without MFA-enabled).
1.In devops, navigate to the Project Settings
-> Service connections
-> New service connection
-> Azure Classic
.
Then input the information, you could get the subscription name and id in the azure portal -> Subscriptions.
Note: The Username
and Password
need to be the user account without MFA-enabled.
2.After creating the service connection, in the pipline, create a Azure powershell task with Task version 3.*
, select the Azure Connection Type
with Azure Classic
, select Azure Classic Subscription
with the service connection which was created in step 1.
Then use the script:
Select-AzureSubscription -SubscriptionName <subscription-name> -Current
CloudServices = Get-AzureService | select ServiceName
Upvotes: 1