Forum Discussion
Empowering Teammates to Dynamically Set Azure Subscriptions in Azure DevOps Pipelines
Your solution is not working. It is taking the Azure Subscription that is set in my Powershell. In my machine subscription "B" is set. So, I have cleared all my set subscriptions in my PowerShell by this command Clear-AzContext -Force. After that, my teammate set the Azure subscription in his machine-like he set a subscription "A".Now it should take subscription "A" and generate an assessment report about subscription "A". So, when he ran this command to trigger my pipeline az pipelines run --name AssessmentTool_Report-CI --orghttps://dev.azure.com/DheemanDas--project test. But It is taking the subscription "B" that is set in my machine. But I have cleared all my set subscriptions in the machine using this command Clear-AzContext -Force. Then why it is taking subscription B Why it is not taking my teammate's subscription that he set in his machine?
Can you please help me to solve this issue? How can I fix it permanently?
- If you do not have one already, create an AzureRM Service Connection in Azure DevOps. Grant the Service Principal the appropriate role in each subscription that you want it to read from (likely reader would be sufficient). Copy the Service Connection's ID to the clipboard.
- In your pipeline, add this new powershell task. This will "target" the Service Connection to the subscriptionId that was passed in.
- pwsh: Write-Host "##vso[task.setendpoint id={YOUR SERVICE CONNECTION ID HERE};field=dataParameter;key=subscriptionId]${{ parameters.SubscriptionId }}"
displayName: Set Subscription
3. Then change the task type for your script that you wrote. Use the Azure CLI task with powershell and use this Service Connection that you created. Now it should authenticate to the subscription you passed in and execute your script in that context. It will not matter what you logged into last on your local machine.
- DheemanSep 12, 2023Copper ContributorHi Jacob,
I am using the azure classic editor pipeline. How can I apply the 2nd and 3rd steps?
please help me:)- Jacob_PetersonSep 12, 2023Copper Contributor