You can define variables and their scope in Azure DevOps pipeline. Variables give you 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 you can then use in your pipeline. All variables are stored as strings and are mutable. The value of a variable can change from run to run or job to job of your pipeline.
The following pipeline can be used to understand the scope of variables defined at root, stage and job level.
In the YAML file, you can set a variable at various scopes:
At the root level, to make it available to all jobs in the pipeline.
At the stage level, to make it available only to a specific stage.
At the job level, to make it available only to a specific job.
When a variable is defined at the top of a YAML, it will be available to all jobs and stages in the pipeline and is a global variable. Global variables defined in a YAML are not visible in the pipeline settings UI.
Variables at the job level override variables at the root and stage level. Variables at the stage level override variables at the root level. A variable set in the pipeline root level will override a variable set in the Pipeline settings UI.
A variable defined at the job level can override a variable set at the stage level. A variable defined at the stage level will override a variable set at the pipeline root level. A variable set in the pipeline root level will override a variable set in the Pipeline settings UI.
Publishing a Docker image to Amazon Elastic Container Registry (ECR) is a bit different than it works with other containers. In this article, you will learn how to build and publish a Docker image using Github Actions (workflow).