I had a question from a customer recently about what happens when two variable groups containing the same variable are linked to the same build or release in Azure Pipelines.
The answer to this is “it depends” and it actually depends on several different factors.
Behaviour in YAML pipelines vs “traditional”/classic pipelines
The behaviour in YAML is that the variable that was set last during the execution takes precedence.
This is a very clear way of handling it. In Classic pipelines the behaviour can be a bit more confusing.
The general order of precedence is…
- Variable set at queue time
- Variable set in the pipeline
- Variable set in the variable group
…in that order. So things injected at queue time will always be used first, then pipeline variables, then content from variable groups.
In a scenario where variable names collide though the documentation says the following.
At present, variables in different groups that are linked to a pipeline in the same scope (e.g., job or stage) will collide and the result may be unpredictable. Ensure that you use different names for variables across all your variable groups.