Problem
I have an azure pipeline YAML file. It is able to run through a service connection which accesses a service principal with all the proper authority, etc.
But I am now trying to clean up the code; we have multiple service principals running on multiple subscriptions and resource groups. They need to create storage accounts, which need to be unique.
So I am trying to create a storage account built partially from the associated subscription and resource group of the service principal creating the storage account.
Example Solution
For the subscription, it is fairly easy. I can do something like this, from within a PowerShell script called inside the pipeline:
$subscriptionId = $(az account show --query 'id' -o tsv)
Write-Output "##vso[task.setvariable variable=AZURE_SUBSCRIPTION_ID;isoutput=true;issecret=true]$subscriptionId"
Now I have the variables $subscription ID
and AZURE_SUBSCRIPTION_ID
set, and can access subscription information within the pipeline itself.
Question
But how can I do something similar with resource groups?
There is no equivalent to az account show
with resource groups, without knowing the resource group name itself. (Eg, I have to type az group show -name <RG-name>
, but it is precisely the name that I am trying to get.)
Again, to be clear, I am running inside of a particular resource group and subscription, it is those that are associated with the service connection. Now I simply want that information available to the pipeline.
am running inside of a particular resource group
A service connection using a SP is only scoped to either Subscription or Management Group – silentaz group list
gives me a list, and I am not sure the list is deterministic (that, for instance, the group I want is always #2 on the list), and (2) this seems like a very fragile way to build a pipeline: that number on the list will be different each time. – Mike Williamson