Azure DevOps Predefined Variables

Share

Azure DevOps Predefined Variables

Azure DevOps predefined variables are a set of predefined system variables provided by Azure DevOps that are available in each build, release, and deployment pipeline. These variables are automatically set by Azure DevOps and can be used without any manual intervention. They offer valuable information about the current context of the pipeline run, such as build ID, build number, job name, agent information, and more. Here’s a brief overview of some key predefined variables and their typical usage:

Commonly Used Predefined Variables

  1. Build Variables

    • Build.BuildId: The ID of the build.
    • Build.BuildNumber: The number of the current build.
    • Build.DefinitionName: The name of the build definition.
    • Build.Repository.Name: The name of the repository.
    • Build.SourceBranch: The branch that is being built.
    • Build.SourceVersion: The latest commit ID of the source code.
  2. Release Variables

    • Release.ReleaseId: The ID of the release.
    • Release.ReleaseName: The name of the current release.
    • Release.EnvironmentName: The name of the release environment.
  3. Agent Variables

    • Agent.Id: The ID of the agent.
    • Agent.MachineName: The name of the machine where the agent is installed.
    • Agent.JobName: The name of the job being executed.
  4. System Variables

    • System.TeamProject: The name of the team project.
    • System.TeamFoundationCollectionUri: The URL of the Azure DevOps server or Azure DevOps Services collection.
    • System.DefaultWorkingDirectory: The default working directory for the pipeline.
  5. Pipeline Variables

    • Pipeline.Workspace: The directory that contains subdirectories for sources, artifacts, etc.

Using Predefined Variables

  • In Tasks: You can use these variables in your tasks and scripts. For example, using $(Build.BuildNumber) in a script within your pipeline will get replaced with the actual build number during runtime.

  • Conditional Insertion: They can be used to conditionally insert steps, jobs, or stages, depending on the value of the variable.

  • Environment Configuration: Useful for configuring environments dynamically based on the context of the pipeline run.

Accessing Variables

  • Syntax: The syntax for using these variables is slightly different depending on the context. In most cases, you can use $(VariableName) syntax. In scripts, you might need to use environment variable syntax like %VARIABLE_NAME% for Windows batch, $VARIABLE_NAME for Linux and macOS scripts, or $env:VARIABLE_NAME for PowerShell.

Customizing and Overriding Variables

  • Custom Variables: In addition to predefined variables, you can define your own custom variables at various scopes (pipeline, stage, job, etc.).
  • Overriding: Some predefined variables can be overridden by specifying the value in the pipeline configuration.

Azure DevOps predefined variables provide a powerful way to access system-level information and use it for various tasks in your CI/CD pipelines, thereby increasing the flexibility and dynamism of your automated processes.

Demo Day 1 Video:

You can find more information about DevOps in this DevOps Link

 

Conclusion:

Unogeeks is the No.1 IT Training Institute for DevOps Training. Anyone Disagree? Please drop in a comment

You can check out our other latest blogs on  DevOps here – DevOps Blogs

You can check out our Best In Class DevOps Training Details here – DevOps Training

💬 Follow & Connect with us:

———————————-

For Training inquiries:

Call/Whatsapp: +91 73960 33555

Mail us at: info@unogeeks.com

Our Website ➜ https://unogeeks.com

Follow us:

Instagram: https://www.instagram.com/unogeeks

Facebook:https://www.facebook.com/UnogeeksSoftwareTrainingInstitute

Twitter: https://twitter.com/unogeeks


Share

Leave a Reply

Your email address will not be published. Required fields are marked *