Forum Discussion
Dheeman
Sep 08, 2023Copper Contributor
Empowering Teammates to Dynamically Set Azure Subscriptions in Azure DevOps Pipelines
Hi, I have a query regarding my Azure DevOps Pipeline. I am running a DevOps pipeline where I am running a PowerShell script that will generate an assessment report about my Azure subscription. In t...
Jacob_Peterson
Sep 12, 2023Copper Contributor
- 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.
Dheeman
Sep 12, 2023Copper Contributor
Hi Jacob,
I am using the azure classic editor pipeline. How can I apply the 2nd and 3rd steps?
please help me:)
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
Please convert your pipeline to YAML. You can find some MS documentation https://learn.microsoft.com/en-us/azure/devops/pipelines/create-first-pipeline?view=azure-devops&tabs=java%2Ctfs-2018-2%2Cbrowser.