Get in Touch With Us

Submitting the form below will ensure a prompt response from us.

In Azure DevOps, variables play a crucial role in automating builds and deployments. They help store data that can be reused across pipelines, such as configuration settings, environment values, or custom logic. Among these, predefined variables are system-generated variables that Azure DevOps provides out of the box. These variables make it easier for developers and DevOps engineers to access useful metadata during pipeline execution.

What are Azure DevOps Predefined Variables?

Azure DevOps Predefined Variables are automatically set by the system and contain context-specific information. These variables can represent data such as the build number, pipeline name, agent details, repository information, source branch, and more. You can use them in both YAML and Classic pipelines.

They are particularly helpful when you want to:

  • Log the current pipeline or job details
  • Reference repository metadata
  • Automate branching logic
  • Identify the agent or system environment
  • Handle conditions dynamically in your scripts

Categories of Predefined Variables

Azure DevOps predefined variables are categorized into several groups depending on the purpose and context:

System Variables

These variables provide information about the running pipeline, project, job, and system environment.

Common Examples:

  • Build.BuildId – The unique ID of the build.
  • Build.BuildNumber – The build number displayed in the UI.
  • System.DefinitionId – The pipeline definition ID.
  • System.JobAttempt – Indicates how many times a job has been attempted.

Agent Variables

These variables provide details about the build/release agent used to run the pipeline.

Examples:

  • Agent.Name – Name of the agent.
  • Agent.MachineName – The machine name of the agent.
  • Agent.OS – Operating system of the agent.
  • Agent.Version – The version of the agent.

Build Variables

These are specific to build pipelines and include details like source branch, repository name, and more.

Examples:

  • Build.Repository.Name – The name of the repository.
  • Build.SourceBranch – The branch name that triggered the build.
  • Build.SourceVersion – The latest commit SHA.

Release Variables

Used in release pipelines (Classic), these variables store data specific to deployment environments.

Examples:

  • Release.ReleaseId – The ID of the release.
  • Release.EnvironmentName – Name of the environment where the release is running.
  • Release.Artifacts.<alias>.SourceBranch – The source branch of an artifact.

Job and Stage Variables

These variables reflect the current job or stage execution details.

Examples:

  • System.JobName – The name of the current job.
  • System.StageName – The name of the current stage in the pipeline.

How to Use Azure DevOps Predefined Variables

In YAML pipelines, predefined variables can be referenced using either the $(variableName) syntax for scripts or as expressions using variables[‘variableName’].

Example:

yaml

steps:
- script: echo "Running on branch: $(Build.SourceBranch)"

In Classic pipelines, you can access these variables similarly within task inputs or inline scripts.

Are Predefined Variables Secure?

Some variables, such as those that store secrets or sensitive info, are treated as secure. These are not logged in plain text and should be accessed with care.

  • Secure Variables cannot be echoed directly.
  • To protect sensitive data, use Azure DevOps secret variables stored in the Library with the Keep this value secret option enabled.

Things to Keep in Mind

  • Predefined variables are read-only. You cannot overwrite them.
  • Their values may differ depending on the pipeline type (YAML vs Classic).
  • Some variables may be undefined in certain contexts if they don’t apply (e.g., build variables in a release pipeline).

Useful Scenario: Branch-Specific Tasks

Suppose you only want to run a deployment step when the pipeline is triggered by a main branch. You can use a predefined variable like this:

yaml

- script: echo "Deploying to Production"
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')

Conclusion

Azure DevOps predefined variables are powerful tools that provide insights into the pipeline runtime environment, helping developers write more dynamic and intelligent pipelines. Whether you’re building, testing, or deploying, these variables let you work with automation efficiently—without hardcoding values or duplicating logic.

Understanding how to leverage Azure DevOps Predefined Variables is essential for building robust, flexible CI/CD pipelines as part of effective Microsoft Azure Development practices. Be sure to explore Microsoft’s official documentation for a complete list and advanced use cases.

About Author

Jayanti Katariya is the CEO of Moon Technolabs, a fast-growing IT solutions provider, with 18+ years of experience in the industry. Passionate about developing creative apps from a young age, he pursued an engineering degree to further this interest. Under his leadership, Moon Technolabs has helped numerous brands establish their online presence and he has also launched an invoicing software that assists businesses to streamline their financial operations.

Related Q&A