These variables are automatically set by Azure Pipelines and can be used to simplify your build and deployment processes.
They're available in all Azure Pipelines jobs and can be referenced in your pipeline YAML files.
You can access these variables in your pipeline YAML files using the syntax $(variablename).
Azure DevOps Environment
Azure DevOps automatically injects system-defined variables into the pipeline environment.
These variables include the Build Number, a unique identifier for the specific build being executed in the pipeline, and the Source Branch, which indicates the source code branch from which the pipeline is being triggered.
The Repository URL is also automatically injected, providing the URL of the source code repository associated with the pipeline.
These automatic variables are accessible to tasks within the pipeline as environment variables, allowing them to be utilized during the execution of tasks.
You can also define custom variables within your pipeline YAML configuration, which are used to store specific configuration values set up to a particular job or stage within the pipeline.
Here are some examples of agent-specific variables that can be configured:
- Paths: directory paths where specific files or resources are located on the agent machine.
- Usernames: usernames align with the agent machine, used for authentication or authorization purposes.
- License Keys: unique keys or codes specific to the agent machine, used to validate and enable certain software or services.
Azure DevOps Agent Capabilities
Azure DevOps Agent Capabilities are a crucial aspect of Azure DevOps pipelines. They influence the execution of tasks across different agents.
In Azure DevOps pipelines, agents have capabilities that determine what tasks they can execute. These capabilities are not enabled by default and must be explicitly specified in the pipeline configuration.
Azure DevOps provides a list of available capabilities that can be enabled for agents, including capabilities for running tasks that require specific tools or software.
System Variables
System variables are an essential part of Azure DevOps environment. They provide valuable information about the pipeline, build, and repository.
You can access system variables in your pipeline YAML configuration, and they can be used as environment variables in tasks. Examples of system variables include the build number, source branch, and repository URL.
System variables are automatically injected into the pipeline environment by Azure DevOps. This makes them easily accessible during pipeline execution.
Some common system variables include the build number, source branch, and repository URL. These variables are automatically injected into the pipeline environment and can be used as environment variables in tasks.
Here is a list of some common system variables:
These system variables can be used to customize and automate your pipeline.
Azure Pipelines Variables
Azure Pipelines Variables are a powerful tool that allows you to store and manage configuration values in your pipeline. You can define custom variables in your pipeline YAML configuration to store specific configuration values.
Azure Pipelines automatically injects system-defined variables into the pipeline environment, which include the Build Number, Source Branch, and Repository URL. These variables are accessible to tasks within the pipeline as environment variables.
You can use agent variables as environment variables in your scripts and build tasks, but not to customize the build number or apply a version control label or tag. Some examples of agent variables include Agent.BuildDirectory, Agent.ContainerMapping, and Agent.JobName.
Here are some common agent variables:
You can also access predefined variables in YAML pipeline using methods like $(System.PullRequest.SourceBranch) or $SYSTEM_PULLREQUEST_SOURCEBRANCH.
Agent Variables
Agent variables are a type of variable that is automatically injected into your pipeline by Azure DevOps. These variables provide information about the agent machine, such as its ID, name, and operating system.
The agent variables are accessible as environment variables in your scripts and build tasks. They are not customizable, but rather a way for Azure DevOps to provide you with information about the agent machine.
Here are some examples of agent variables:
Deployment Job Variables
Deployment Job Variables are a crucial part of Azure Pipelines, allowing you to store and retrieve values that can be used during deployment.
You can access these variables in your deployment jobs, and they're scoped to a specific job, meaning they'll only be resolved at job execution time.
The Environment.Name variable holds the name of the environment targeted in the deployment job, such as smarthotel-dev.
The Environment.Id variable stores the ID of the environment targeted in the deployment job, which might be 10.
You can also use Environment.ResourceName to get the name of the specific resource within the environment, like bookings, a Kubernetes namespace.
Similarly, Environment.ResourceId holds the ID of the specific resource within the environment, which could be 4.
Deployment strategies like canary, runOnce, or rolling are represented by the Strategy.Name variable.
The Strategy.CycleName variable holds the current cycle name in a deployment, which can be PreIteration, Iteration, or PostIteration.
Here's a summary of the deployment job variables:
Identity Set Status
When you're working with Azure Pipelines, it's essential to understand how identity variables are set. The value depends on what caused the build and is specific to Azure Repos repositories.
The identity variables can be set based on the system identity, which is represented by [DefaultCollection]\Project Collection Service Accounts. This is the case when the build is triggered by Git or Continuous integration (CI) triggers, or by a scheduled trigger.
The person who pushed or checked in the changes is another key factor in setting the identity variables. This is true when the build is triggered by a branch policy build, or by a gated check-in trigger in TFVC.
You, the user, also have a role in setting the identity variables. This happens when you click the Queue build button, making you the person responsible for the build.
Here's a summary of the identity variables set based on the build trigger:
Precedence and Expansion
Variables in Azure Pipelines can be defined at various scopes, and it's essential to understand the precedence rules to avoid conflicts.
If you define a variable with the same name at more than one scope, you need to be aware of the precedence rules, which can be read about in the documentation.
Variables are expanded at the beginning of the run, and also before each step, which can affect the availability of their values.
This expansion process can be seen in an example that demonstrates how variables are expanded at different stages of the pipeline.
Sources
- https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables
- https://colinsalmcorner.com/azure-pipeline-variables/
- https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/resources-pipelines-pipeline
- https://copdips.com/2022/01/azure-pipeline-predefined-variables.html
- https://bobcares.com/blog/azure-devops-agent-capabilities-and-environment-variables/
Featured Images: pexels.com