Проверка подлинности сценария PowerShell с помощью AccessToken - PullRequest
0 голосов
/ 21 июня 2020

У меня есть конвейер выпуска, который вызывает сценарий PowerShell, и у него есть оператор Select-AzureSubscription (в al oop мне нужно назначить разные подписки как текущие и выполнить какой-то процесс). Когда он запускается, я получаю следующую ошибку, поскольку я не добавил «Add-AzureAccount».

Select-AzureSubscription: имя подписки не существует.

Есть ли способ аутентифицировать или выполнить Add-AzureAccount с помощью токена доступа конвейера.

Код: -

Select-AzureSubscription -SubscriptionName $Subscription -Current 
CloudServices = Get-AzureService | select ServiceName 

1 Ответ

1 голос
/ 22 июня 2020

Вы можете попробовать следующие шаги (я не смог протестировать его для вас, поскольку у меня нет учетной записи без поддержки MFA).

1. В DevOps перейдите к Project Settings - > Service connections -> New service connection -> Azure Classic.

enter image description here

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.

enter image description here

enter image description here

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  -Current 
CloudServices = Get-AzureService | select ServiceName 

введите описание изображения здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...