I have a job with some steps in an Azure DevOps pipeline that I want to run multiple times, each time with a different variable group. Here is a minimal example:
strategy:
matrix:
Customer:
variableGroupName: 'Customer variables'
Test:
variableGroupName: 'Test variables'
pool:
vmImage: 'windows-latest'
variables:
- group: $(variableGroupName)
steps:
- script: echo $(MyVariable)
However, it yields this error when trying to run the pipeline:
An error occurred while loading the YAML build pipeline. Variable group was not found or is not authorized for use. For authorization details, refer to https://aka.ms/yamlauthz.
How can I change the configuration so that the variable group name gets set differently each run?
2
Answers
Based on what Robert wrote, I ended up with this solution:
I'm marking his answer as the accepted answer. But just for the sake of completeness, my code is here as well. I changed the indentation, added a
displayName
property to thevariableGroups
, and I don't think${{ environment.name }}
worked for me so I changed the name of the jobs.What I find useful in these scenarios is a for each loop over the items I have, in your case a collection of variable groups.
Here’s an updated code snippet: