How to configure and use a Yaml reference file in Azure DevOps.

Tzahi Kolber
2 min readJun 8, 2023

In this blog I will describe and demonstrate, how to use a Yaml reference file in Azure DevOps.
Using a Yaml reference file, makes the configuration of multiple Yaml files easier and efficient, along with saving a lot of work and code writing.

What is a Yaml reference file?

A Yaml reference file is actually a main settings file which contains most of the repetitive configuration we are going to use in our environment.
For example, in case we are building environment with the same parameters as prefix, hosted agent pool, region, service connection, resource group name or other parameters, we can config a different variable for each of our names and those variables will point to the parameters in the Yaml reference file.

The next Yaml file is an example for a reference file which contains those parameters we are going to use later on again and again in our Yaml pipelines:

variables:

# Environment Configs — General
MyResourceGroup: “GHESRSG” # RG name for devops resources
region: “westeurope” # Used for provisioning of all resources
regionPrefix: “we” # Used in resource names
MyServiceConnection: “DEMOSA” # The name pf the service connection creted for the subscription
MyPoolName: “Hosted Windows 2019 with VS2019” # The self hosted agents pool name you created in ADO

In this example the file called Shared.ref.conf.yml is located at the conf directory in my repository.

Pointing and using the Yaml reference file

So, after we created our Yaml reference file, we can start pointing all our Yaml files which are going to be used with the same common parameters in the Yaml reference file.
There are only 2 things we need to do:

  1. To point the reference file in our Yaml file, we need to config the variables which will point the template to the location of the Yaml reference path file, including its name:
    variables:
    - template: ../conf/shared.ref.conf.yml
  2. Config every variable at the next syntax instead of coding each time the parameter needed:
    $(myvariable)

In this way you can just change your parameters once at the Yaml reference file instead of going over all your Yaml files and change them one after the other.

Conclusion

A Yaml reference file is a very simple and easy way to handle changing multiple parameters from a single location, only once, instead of reviewing many Yaml files and changing the parameters inside each one of them, which also may lead to a lot of human errors like misspelling or forgetting changing parameters.

--

--

Tzahi Kolber

During the last 15 years, I was working as a Senior PFE within Exchange area at Microsoft. Now I’m Senior Consult as Azure IAAS, PowerShell & Automations.