Usage of Variable Template in Azure DevOps Pipelines
Author: Akhil M Anil || DevOps Engineer
Let's understand what variables in Azure DevOps are:
Variables give us a convenient way to get key bits of data into various parts of the pipeline. The most common use of variables is to define a value that we can then use in our pipeline. The value of a variable can change from run to run or job to job in your pipeline.
Different types of variables are:
- User-defined variables
- System variables
- Environment variables
User-defined Variables
The variables defined by the user are called user-defined variables. In YAML pipelines, we can set variables at the root, stage, and job levels. We can use a variable group to make variables available across multiple pipelines or we can use templates to define variables that are used in multiple pipelines in one file.
In this blog, we will discuss variables defined in a template file and create a simple pipeline for getting variables from the variable template.
Advantages of using Variable Templates over Variable Groups:
- YAML template variables can be expanded at compile-time, and variables defined in variable groups can only be expanded at runtime.
- For YAML templates, whatever changes are done in the variable templates are available in the history of the repository where the file resides whereas in Variable groups the last changed user's name will be available unless it is connected to any log analytics workspace.
- YAML templates offer more freedom in terms of the structure of the data.
Variable Template definition
Steps:
Here in the pipeline, we have defined two scripts one for fetching values from the variable group and another for fetching values from the variable template.
Now let's run the pipeline.
LinkedIn: Akhil M Anil | LinkedIn
Comments
Post a Comment