Use predefined variables
Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 - TFS 2015
Note
In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.
Variables give you a convenient way to get key bits of data into various parts of your pipeline. This is the comprehensive list of predefined variables.
These variables are automatically set by the system and read-only. (The exceptions are Build.Clean and System.Debug.) Learn more about working with variables.
Note
You can use release variables in your deploy tasks to share the common information (e.g. — Environment Name, Resource Group, etc)
Build.Clean
This is a deprecated variable that modifies how the build agent cleans up source. To learn how to clean up source, see Clean the local repo on the agent.
This variable modifies how the build agent cleans up source. To learn more, see Clean the local repo on the agent.
System.AccessToken
System.AccessToken
is a special variable that carries the security token used by the running build.
In YAML, you must explicitly map System.AccessToken
into the pipeline using a
variable. You can do this at the step or task level:
steps:
- bash: echo This script could use $SYSTEM_ACCESSTOKEN
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- powershell: Write-Host "This is a script that could use $env:SYSTEM_ACCESSTOKEN"
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
You can configure the default scope for System.AccessToken
using build job authorization scope.
System.Debug
For more detailed logs to debug pipeline problems, define System.Debug
and set it to true
.
Edit your pipeline.
Select Variables.
Add a new variable with the name
System.Debug
and valuetrue
.Save the new variable.
Agent variables (DevOps Services)
Note
You can use agent variables as environment variables in your scripts and as parameters in your build tasks. You cannot use them to customize the build number or to apply a version control label or tag.
Variable | Description |
---|---|
Agent.BuildDirectory |
The local path on the agent where all folders for a given build pipeline are created. This variable has the same value as For example: |
Agent.ContainerMapping |
A mapping from container resource names in YAML to their Docker IDs at runtime. For example: |
Agent.HomeDirectory | The directory the agent is installed into. This contains the agent software. For example: c:\agent . |
Agent.Id | The ID of the agent. |
Agent.JobName | The name of the running job. This will usually be "Job" or "__default", but in multi-config scenarios, will be the configuration. |
Agent.JobStatus | The status of the build.
The environment variable should be referenced as |
Agent.MachineName | The name of the machine on which the agent is installed. |
Agent.Name |
The name of the agent that is registered with the pool. If you are using a self-hosted agent, then this name is specified by you. See agents. |
Agent.OS |
The operating system of the agent host. Valid values are:
|
Agent.OSArchitecture |
The operating system processor architecture of the agent host. Valid values are:
|
Agent.TempDirectory |
A temporary folder that is cleaned after each pipeline job. This directory is used by tasks such as .NET Core CLI task to hold temporary items like test results before they are published. For example: |
Agent.ToolsDirectory |
The directory used by tasks such as Node Tool Installer and Use Python Version to switch between multiple versions of a tool.
These tasks will add tools from this directory to PATH so that subsequent build steps can use them.
Learn about managing this directory on a self-hosted agent. |
Agent.WorkFolder |
The working directory for this agent.
For example: c:\agent_work .
Note: This directory is not guaranteed to be writable by pipeline tasks (eg. when mapped into a container) |
Build variables (DevOps Services)
Variable | Description | Available in templates? |
---|---|---|
Build.ArtifactStagingDirectory |
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
No |
Build.BuildId | The ID of the record for the completed build. | No |
Build.BuildNumber | The name of the completed build, also known as the run number. You can specify what is included in this value. A typical use of this variable is to make it part of the label format, which you specify on the repository tab. Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail.
|
No |
Build.BuildUri | The URI for the build. For example: vstfs:///Build/Build/1430 .
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.BinariesDirectory | The local path on the agent you can use as an output folder for compiled binaries.
By default, new build pipelines are not set up to clean this directory. You can define your build to clean it up on the Repository tab. For example: c:\agent_work\1\b .
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.ContainerId | The ID of the container for your artifact. When you upload an artifact in your pipeline, it is added to a container that is specific for that particular artifact. | No |
Build.DefinitionName | The name of the build pipeline.
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Yes |
Build.DefinitionVersion | The version of the build pipeline. | Yes |
Build.QueuedBy | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Yes |
Build.QueuedById | See "How are the identity variables set?". | Yes |
Build.Reason | The event that caused the build to run.
|
Yes |
Build.Repository.Clean | The value you've selected for Clean in the source repository settings.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.Repository.LocalPath |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.SourcesDirectory. |
No |
Build.Repository.ID | The unique identifier of the repository.
This won't change, even if the name of the repository does. This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.Repository.Name | The name of the triggering repository.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.Repository.Provider | The type of the triggering repository.
|
No |
Build.Repository.Tfvc.Workspace | Defined if your repository is Team Foundation Version Control. The name of the TFVC workspace used by the build agent.
For example, if the Agent.BuildDirectory is c:\agent_work\12 and the Agent.Id is 8 , the workspace name could be: ws_12_8
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.Repository.Uri | The URL for the triggering repository. For example: This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. | No |
Build.RequestedFor | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Yes |
Build.RequestedForEmail | See "How are the identity variables set?". | Yes |
Build.RequestedForId | See "How are the identity variables set?". | Yes |
Build.SourceBranch | The branch of the triggering repo the build was queued for. Some examples:
/ ) are replaced with underscore characters _ ).
Note: In TFVC, if you are running a gated check-in build or manually building a shelveset, you cannot use this variable in your build number format. |
Yes |
Build.SourceBranchName | The name of the branch in the triggering repo the build was queued for.
|
Yes |
Build.SourcesDirectory |
The local path on the agent where your source code files are downloaded. For example: Important note: if you only check out one Git repository, this path will be the exact path to the code. If you check out multiple repositories, it will revert to its default value, which is This variable is synonymous with Build.Repository.LocalPath. |
No |
Build.SourceVersion | The latest version control change of the triggering repo that is included in this build. This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. | Yes |
Build.SourceVersionMessage | The comment of the commit or changeset for the triggering repo. We truncate the message to the first line or 200 characters, whichever is shorter.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. Also, this variable is only available on the step level and is neither available in the job nor stage levels (i.e. the message is not extracted until the job had started and checked out the code). Note: This variable is available in TFS 2015.4. |
No |
Build.StagingDirectory |
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
No |
Build.Repository.Git.SubmoduleCheckout | The value you've selected for Checkout submodules on the repository tab. With multiple repos checked out, this value tracks the triggering repository's setting.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.SourceTfvcShelveset | Defined if your repository is Team Foundation Version Control.
If you are running a gated build or a shelveset build, this is set to the name of the shelveset you are building. Note: This variable yields a value that is invalid for build use in a build number format. |
No |
Build.TriggeredBy.BuildId | If the build was triggered by another build, then this variable is set to the BuildID of the triggering build. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.TriggeredBy.DefinitionId | If the build was triggered by another build, then this variable is set to the DefinitionID of the triggering build. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.TriggeredBy.DefinitionName | If the build was triggered by another build, then this variable is set to the name of the triggering build pipeline. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.TriggeredBy.BuildNumber | If the build was triggered by another build, then this variable is set to the number of the triggering build. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.TriggeredBy.ProjectID | If the build was triggered by another build, then this variable is set to ID of the project that contains the triggering build. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Common.TestResultsDirectory | The local path on the agent where the test results are created. For example: c:\agent_work\1\TestResults
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Pipeline variables (DevOps Services)
Variable | Description |
---|---|
Pipeline.Workspace | Workspace directory for a particular pipeline. This variable has the same value as Agent.BuildDirectory .For example, /home/vsts/work/1 . |
Deployment job variables (DevOps Services)
These variables are scoped to a specific Deployment job and will be resolved only at job execution time.
Variable | Description |
---|---|
Environment.Name | Name of the environment targeted in the deployment job to run the deployment steps and record the deployment history. For example, smarthotel-dev . |
Environment.Id | ID of the environment targeted in the deployment job. For example, 10 . |
Environment.ResourceName | Name of the specific resource within the environment targeted in the deployment job to run the deployment steps and record the deployment history. For example, bookings which is a Kubernetes namespace that has been added as a resource to the environment smarthotel-dev . |
Environment.ResourceId | ID of the specific resource within the environment targeted in the deployment job to run the deployment steps. For example, 4 . |
System variables (DevOps Services)
Variable | Description | Available in templates? |
---|---|---|
System.AccessToken | Use the OAuth token to access the REST API.
Use System.AccessToken from YAML scripts. This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Yes |
System.CollectionId | The GUID of the TFS collection or Azure DevOps organization. | Yes |
System.CollectionUri | The URI of the TFS collection or Azure DevOps organization. For example: https://dev.azure.com/fabrikamfiber/ . |
Yes |
System.DefaultWorkingDirectory |
The local path on the agent where your source code files are downloaded. For example: |
No |
System.DefinitionId | The ID of the build pipeline. | Yes |
System.HostType | Set to build if the pipeline is a build. For a release, the values are deployment for a Deployment group job, gates during evaluation of gates, and release for other (Agent and Agentless) jobs. |
Yes |
System.JobAttempt | Set to 1 the first time this job is attempted, and increments every time the job is retried. | No |
System.JobDisplayName | The human-readable name given to a job. | No |
System.JobId | A unique identifier for a single attempt of a single job. | No |
System.JobName | The name of the job, typically used for expressing dependencies and accessing output variables. | No |
System.PhaseAttempt | Set to 1 the first time this phase is attempted, and increments every time the job is retried. Note: "Phase" is a mostly-redundant concept which represents the design-time for a job (whereas job was the runtime version of a phase). We've mostly removed the concept of "phase" from Azure Pipelines. Matrix and multi-config jobs are the only place where "phase" is still distinct from "job". One phase can instantiate multiple jobs which differ only in their inputs. |
No |
System.PhaseDisplayName | The human-readable name given to a phase. | No |
System.PhaseName | A string-based identifier for a job, typically used for expressing dependencies and accessing output variables. | No |
System.StageAttempt | Set to 1 the first time this stage is attempted, and increments every time the job is retried. | No |
System.StageDisplayName | The human-readable name given to a stage. | No |
System.StageName | A string-based identifier for a stage, typically used for expressing dependencies and accessing output variables. | Yes |
System.PullRequest.IsFork | If the pull request is from a fork of the repository, this variable is set to True .
Otherwise, it is set to False . |
Yes |
System.PullRequest.PullRequestId | The ID of the pull request that caused this build. For example: 17 . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy). |
No |
System.PullRequest.PullRequestNumber | The number of the pull request that caused this build. This variable is populated for pull requests from GitHub which have a different pull request ID and pull request number. This variable is only available in a YAML pipeline if the PR is a affected by a branch policy. | No |
System.PullRequest.SourceBranch | The branch that is being reviewed in a pull request. For example: refs/heads/users/raisa/new-feature . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy). This variable is only available in a YAML pipeline if the PR is affected by a branch policy. |
No |
System.PullRequest.SourceRepositoryURI | The URL to the repo that contains the pull request. For example: https://dev.azure.com/ouraccount/_git/OurProject . |
No |
System.PullRequest.TargetBranch | The branch that is the target of a pull request. For example: refs/heads/master when your repository is in Azure Repos and master when your repository is in GitHub. This variable is initialized only if the build ran because of a Git PR affected by a branch policy. This variable is only available in a YAML pipeline if the PR is affected by a branch policy. |
No |
System.TeamFoundationCollectionUri | The URI of the TFS collection or Azure DevOps organization. For example: https://dev.azure.com/fabrikamfiber/ .
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Yes |
System.TeamProject | The name of the project that contains this build. | Yes |
System.TeamProjectId | The ID of the project that this build belongs to. | Yes |
TF_BUILD | Set to True if the script is being run by a build task.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Checks variables (DevOps Services)
Variable | Description |
---|---|
Checks.StageAttempt | Set to 1 the first time this stage is attempted, and increments every time the stage is retried.
This variable can only be used within an approval or check for an environment. For example, you could use $(Checks.StageAttempt) within an Invoke REST API check. |
Agent variables (DevOps Server 2020)
Note
You can use agent variables as environment variables in your scripts and as parameters in your build tasks. You cannot use them to customize the build number or to apply a version control label or tag.
Variable | Description |
---|---|
Agent.BuildDirectory |
The local path on the agent where all folders for a given build pipeline are created. This variable has the same value as For example: |
Agent.HomeDirectory | The directory the agent is installed into. This contains the agent software. For example: c:\agent . |
Agent.Id | The ID of the agent. |
Agent.JobName | The name of the running job. This will usually be "Job" or "__default", but in multi-config scenarios, will be the configuration. |
Agent.JobStatus | The status of the build.
The environment variable should be referenced as |
Agent.MachineName | The name of the machine on which the agent is installed. |
Agent.Name |
The name of the agent that is registered with the pool. If you are using a self-hosted agent, then this name is specified by you. See agents. |
Agent.OS |
The operating system of the agent host. Valid values are:
|
Agent.OSArchitecture |
The operating system processor architecture of the agent host. Valid values are:
|
Agent.TempDirectory |
A temporary folder that is cleaned after each pipeline job. This directory is used by tasks such as .NET Core CLI task to hold temporary items like test results before they are published. For example: |
Agent.ToolsDirectory |
The directory used by tasks such as Node Tool Installer and Use Python Version to switch between multiple versions of a tool.
These tasks will add tools from this directory to PATH so that subsequent build steps can use them.
Learn about managing this directory on a self-hosted agent. |
Agent.WorkFolder |
The working directory for this agent.
For example: c:\agent_work .
Note: This directory is not guaranteed to be writable by pipeline tasks (eg. when mapped into a container) |
Build variables (DevOps Server 2020)
Variable | Description | Available in templates? |
---|---|---|
Build.ArtifactStagingDirectory |
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
No |
Build.BuildId | The ID of the record for the completed build. | No |
Build.BuildNumber | The name of the completed build, also known as the run number. You can specify what is included in this value. A typical use of this variable is to make it part of the label format, which you specify on the repository tab. Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail.
|
No |
Build.BuildUri | The URI for the build. For example: vstfs:///Build/Build/1430 .
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.BinariesDirectory | The local path on the agent you can use as an output folder for compiled binaries.
By default, new build pipelines are not set up to clean this directory. You can define your build to clean it up on the Repository tab. For example: c:\agent_work\1\b .
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.ContainerId | The ID of the container for your artifact. When you upload an artifact in your pipeline, it is added to a container that is specific for that particular artifact. | No |
Build.DefinitionName | The name of the build pipeline.
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Yes |
Build.DefinitionVersion | The version of the build pipeline. | Yes |
Build.QueuedBy | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Yes |
Build.QueuedById | See "How are the identity variables set?". | Yes |
Build.Reason | The event that caused the build to run.
|
Yes |
Build.Repository.Clean | The value you've selected for Clean in the source repository settings.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.Repository.LocalPath |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.SourcesDirectory. |
No |
Build.Repository.ID | The unique identifier of the repository.
This won't change, even if the name of the repository does. This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.Repository.Name | The name of the triggering repository.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.Repository.Provider | The type of the triggering repository.
|
No |
Build.Repository.Tfvc.Workspace | Defined if your repository is Team Foundation Version Control. The name of the TFVC workspace used by the build agent.
For example, if the Agent.BuildDirectory is c:\agent_work\12 and the Agent.Id is 8 , the workspace name could be: ws_12_8
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.Repository.Uri | The URL for the triggering repository. For example: This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. | No |
Build.RequestedFor | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Yes |
Build.RequestedForEmail | See "How are the identity variables set?". | Yes |
Build.RequestedForId | See "How are the identity variables set?". | Yes |
Build.SourceBranch | The branch of the triggering repo the build was queued for. Some examples:
/ ) are replaced with underscore characters _ ).
Note: In TFVC, if you are running a gated check-in build or manually building a shelveset, you cannot use this variable in your build number format. |
Yes |
Build.SourceBranchName | The name of the branch in the triggering repo the build was queued for.
|
Yes |
Build.SourcesDirectory |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.Repository.LocalPath. |
No |
Build.SourceVersion | The latest version control change of the triggering repo that is included in this build. This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. | Yes |
Build.SourceVersionMessage | The comment of the commit or changeset for the triggering repo. We truncate the message to the first line or 200 characters, whichever is shorter.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. Also, this variable is only available on the step level and is neither available in the job nor stage levels (i.e. the message is not extracted until the job had started and checked out the code). Note: This variable is available in TFS 2015.4. |
No |
Build.StagingDirectory |
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
No |
Build.Repository.Git.SubmoduleCheckout | The value you've selected for Checkout submodules on the repository tab. With multiple repos checked out, this value tracks the triggering repository's setting.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.SourceTfvcShelveset | Defined if your repository is Team Foundation Version Control.
If you are running a gated build or a shelveset build, this is set to the name of the shelveset you are building. Note: This variable yields a value that is invalid for build use in a build number format. |
No |
Build.TriggeredBy.BuildId | If the build was triggered by another build, then this variable is set to the BuildID of the triggering build. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.TriggeredBy.DefinitionId | If the build was triggered by another build, then this variable is set to the DefinitionID of the triggering build. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.TriggeredBy.DefinitionName | If the build was triggered by another build, then this variable is set to the name of the triggering build pipeline. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.TriggeredBy.BuildNumber | If the build was triggered by another build, then this variable is set to the number of the triggering build. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Build.TriggeredBy.ProjectID | If the build was triggered by another build, then this variable is set to ID of the project that contains the triggering build. In Classic pipelines, this variable is triggered by a build completion trigger.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Common.TestResultsDirectory | The local path on the agent where the test results are created. For example: c:\agent_work\1\TestResults
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Pipeline variables (DevOps Server 2020)
Variable | Description |
---|---|
Pipeline.Workspace | Workspace directory for a particular pipeline. This variable has the same value as Agent.BuildDirectory .For example, /home/vsts/work/1 . |
Deployment job variables (DevOps Server 2020)
These variables are scoped to a specific Deployment job and will be resolved only at job execution time.
Variable | Description |
---|---|
Environment.Name | Name of the environment targeted in the deployment job to run the deployment steps and record the deployment history. For example, smarthotel-dev . |
Environment.Id | ID of the environment targeted in the deployment job. For example, 10 . |
Environment.ResourceName | Name of the specific resource within the environment targeted in the deployment job to run the deployment steps and record the deployment history. For example, bookings which is a Kubernetes namespace that has been added as a resource to the environment smarthotel-dev . |
Environment.ResourceId | ID of the specific resource within the environment targeted in the deployment job to run the deployment steps. For example, 4 . |
System variables (DevOps Server 2020)
Variable | Description | Available in templates? |
---|---|---|
System.AccessToken | Use the OAuth token to access the REST API.
Use System.AccessToken from YAML scripts. This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Yes |
System.CollectionId | The GUID of the TFS collection or Azure DevOps organization | Yes |
System.CollectionUri | A string Team Foundation Server collection URI. | Yes |
System.DefaultWorkingDirectory |
The local path on the agent where your source code files are downloaded. For example: |
No |
System.DefinitionId | The ID of the build pipeline. | Yes |
System.HostType | Set to build if the pipeline is a build. For a release, the values are deployment for a Deployment group job, gates during evaluation of gates, and release for other (Agent and Agentless) jobs. |
Yes |
System.JobAttempt | Set to 1 the first time this job is attempted, and increments every time the job is retried. | No |
System.JobDisplayName | The human-readable name given to a job. | No |
System.JobId | A unique identifier for a single attempt of a single job. | No |
System.JobName | The name of the job, typically used for expressing dependencies and accessing output variables. | No |
System.PhaseAttempt | Set to 1 the first time this phase is attempted, and increments every time the job is retried. Note: "Phase" is a mostly-redundant concept which represents the design-time for a job (whereas job was the runtime version of a phase). We've mostly removed the concept of "phase" from Azure Pipelines. Matrix and multi-config jobs are the only place where "phase" is still distinct from "job". One phase can instantiate multiple jobs which differ only in their inputs. |
No |
System.PhaseDisplayName | The human-readable name given to a phase. | No |
System.PhaseName | A string-based identifier for a job, typically used for expressing dependencies and accessing output variables. | No |
System.StageAttempt | Set to 1 the first time this stage is attempted, and increments every time the job is retried. | No |
System.StageDisplayName | The human-readable name given to a stage. | No |
System.StageName | A string-based identifier for a stage, typically used for expressing dependencies and accessing output variables. | Yes |
System.PullRequest.IsFork | If the pull request is from a fork of the repository, this variable is set to True .
Otherwise, it is set to False . |
Yes |
System.PullRequest.PullRequestId | The ID of the pull request that caused this build. For example: 17 . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy). |
No |
System.PullRequest.PullRequestNumber | The number of the pull request that caused this build. This variable is populated for pull requests from GitHub which have a different pull request ID and pull request number. This variable is only available in a YAML pipeline if the PR is a affected by a branch policy. | No |
System.PullRequest.SourceBranch | The branch that is being reviewed in a pull request. For example: refs/heads/users/raisa/new-feature . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy). This variable is only available in a YAML pipeline if the PR is affected by a branch policy. |
No |
System.PullRequest.SourceRepositoryURI | The URL to the repo that contains the pull request. For example: https://dev.azure.com/ouraccount/_git/OurProject . |
No |
System.PullRequest.TargetBranch | The branch that is the target of a pull request. For example: refs/heads/master when your repository is in Azure Repos and master when your repository is in GitHub. This variable is initialized only if the build ran because of a Git PR affected by a branch policy. This variable is only available in a YAML pipeline if the PR is affected by a branch policy. |
No |
System.TeamFoundationCollectionUri | The URI of the team foundation collection. For example: https://dev.azure.com/fabrikamfiber/
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Yes |
System.TeamProject | The name of the project that contains this build. | Yes |
System.TeamProjectId | The ID of the project that this build belongs to. | Yes |
TF_BUILD | Set to True if the script is being run by a build task.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
No |
Agent variables (DevOps Server 2019)
Note
You can use agent variables as environment variables in your scripts and as parameters in your build tasks. You cannot use them to customize the build number or to apply a version control label or tag.
Variable | Description |
---|---|
Agent.BuildDirectory |
The local path on the agent where all folders for a given build pipeline are created. For example: |
Agent.HomeDirectory | The directory the agent is installed into. This contains the agent software. For example: c:\agent . |
Agent.Id | The ID of the agent. |
Agent.JobName | The name of the running job. This will usually be "Job" or "__default", but in multi-config scenarios, will be the configuration. |
Agent.JobStatus | The status of the build.
The environment variable should be referenced as |
Agent.MachineName | The name of the machine on which the agent is installed. |
Agent.Name |
The name of the agent that is registered with the pool. If you are using a self-hosted agent, then this name is specified by you. See agents. |
Agent.OS |
The operating system of the agent host. Valid values are:
|
Agent.OSArchitecture |
The operating system processor architecture of the agent host. Valid values are:
|
Agent.TempDirectory | A temporary folder that is cleaned after each pipeline job. This directory is used by tasks such as .NET Core CLI task to hold temporary items like test results before they are published. |
Agent.ToolsDirectory |
The directory used by tasks such as Node Tool Installer and Use Python Version to switch between multiple versions of a tool.
These tasks will add tools from this directory to PATH so that subsequent build steps can use them.
Learn about managing this directory on a self-hosted agent. |
Agent.WorkFolder |
The working directory for this agent.
For example: c:\agent_work .
This directory is not guaranteed to be writable by pipeline tasks (eg. when mapped into a container) |
Build variables (DevOps Server 2019)
Variable | Description |
---|---|
Build.ArtifactStagingDirectory |
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
Build.BuildId | The ID of the record for the completed build. |
Build.BuildNumber | The name of the completed build. You can specify the build number format that generates this value in the pipeline options.
A typical use of this variable is to make it part of the label format, which you specify on the repository tab. Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail.
|
Build.BuildUri | The URI for the build. For example: vstfs:///Build/Build/1430 .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.BinariesDirectory | The local path on the agent you can use as an output folder for compiled binaries.
By default, new build pipelines are not set up to clean this directory. You can define your build to clean it up on the Repository tab. For example: c:\agent_work\1\b .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.DefinitionName | The name of the build pipeline.
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.DefinitionVersion | The version of the build pipeline. |
Build.QueuedBy | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.QueuedById | See "How are the identity variables set?". |
Build.Reason | The event that caused the build to run.
|
Build.Repository.Clean | The value you've selected for Clean in the source repository settings.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.LocalPath |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.SourcesDirectory. |
Build.Repository.Name | The name of the repository.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.Provider | The type of repository you selected.
|
Build.Repository.Tfvc.Workspace | Defined if your repository is Team Foundation Version Control. The name of the TFVC workspace used by the build agent.
For example, if the Agent.BuildDirectory is c:\agent_work\12 and the Agent.Id is 8 , the workspace name could be: ws_12_8
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.Uri | The URL for the repository. For example: This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.RequestedFor | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.RequestedForEmail | See "How are the identity variables set?". |
Build.RequestedForId | See "How are the identity variables set?". |
Build.SourceBranch | The branch the build was queued for. Some examples:
/ ) are replaced with underscore characters _ ).
Note: In TFVC, if you are running a gated check-in build or manually building a shelveset, you cannot use this variable in your build number format. |
Build.SourceBranchName | The name of the branch the build was queued for.
|
Build.SourcesDirectory |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.Repository.LocalPath. |
Build.SourceVersion | The latest version control change that is included in this build. This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.SourceVersionMessage | The comment of the commit or changeset. We truncate the message to the first line or 200 characters, whichever is shorter.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. Note: This variable is available in TFS 2015.4. |
Build.StagingDirectory |
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
Build.Repository.Git.SubmoduleCheckout | The value you've selected for Checkout submodules on the repository tab.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.SourceTfvcShelveset | Defined if your repository is Team Foundation Version Control.
If you are running a gated build or a shelveset build, this is set to the name of the shelveset you are building. Note: This variable yields a value that is invalid for build use in a build number format. |
Build.TriggeredBy.BuildId | If the build was triggered by another build, then this variable is set to the BuildID of the triggering build.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.TriggeredBy.DefinitionId | If the build was triggered by another build, then this variable is set to the DefinitionID of the triggering build.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.TriggeredBy.DefinitionName | If the build was triggered by another build, then this variable is set to the name of the triggering build pipeline.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.TriggeredBy.BuildNumber | If the build was triggered by another build, then this variable is set to the number of the triggering build.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.TriggeredBy.ProjectID | If the build was triggered by another build, then this variable is set to ID of the project that contains the triggering build.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Common.TestResultsDirectory | The local path on the agent where the test results are created. For example: c:\agent_work\1\TestResults
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System variables (DevOps Server 2019)
Variable | Description |
---|---|
System.AccessToken | Use the OAuth token to access the REST API.
Use System.AccessToken from YAML scripts. This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System.CollectionId | The GUID of the TFS collection or Azure DevOps organization |
System.DefaultWorkingDirectory |
The local path on the agent where your source code files are downloaded. For example: |
System.DefinitionId | The ID of the build pipeline. |
System.HostType | Set to build if the pipeline is a build. For a release, the values are deployment for a Deployment group job and release for an Agent job.
|
System.PullRequest.IsFork | If the pull request is from a fork of the repository, this variable is set to True .
Otherwise, it is set to False . |
System.PullRequest.PullRequestId | The ID of the pull request that caused this build. For example: 17 . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy.) |
System.PullRequest.PullRequestNumber | The number of the pull request that caused this build. This variable is populated for pull requests from GitHub which have a different pull request ID and pull request number. |
System.PullRequest.SourceBranch | The branch that is being reviewed in a pull request. For example: refs/heads/users/raisa/new-feature . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy.) |
System.PullRequest.SourceRepositoryURI | The URL to the repo that contains the pull request. For example: https://dev.azure.com/ouraccount/_git/OurProject . (This variable is initialized only if the build ran because of a Azure Repos Git PR affected by a branch policy. It is not initialized for GitHub PRs.) |
System.PullRequest.TargetBranch | The branch that is the target of a pull request. For example: refs/heads/master . This variable is initialized only if the build ran because of a Git PR affected by a branch policy. |
System.TeamFoundationCollectionUri | The URI of the team foundation collection. For example: https://dev.azure.com/fabrikamfiber/ .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System.TeamProject | The name of the project that contains this build. |
System.TeamProjectId | The ID of the project that this build belongs to. |
TF_BUILD | Set to True if the script is being run by a build task.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Agent variables (TFS 2018)
Note
You can use agent variables as environment variables in your scripts and as parameters in your build tasks. You cannot use them to customize the build number or to apply a version control label or tag.
Variable | Description |
---|---|
Agent.BuildDirectory |
The local path on the agent where all folders for a given build pipeline are created. For example: |
Agent.HomeDirectory | The directory the agent is installed into. This contains the agent software. For example: c:\agent . |
Agent.Id | The ID of the agent. |
Agent.JobStatus | The status of the build.
The environment variable should be referenced as |
Agent.MachineName | The name of the machine on which the agent is installed. |
Agent.Name |
The name of the agent that is registered with the pool. This name is specified by you. See agents. |
Agent.TempDirectory | A temporary folder that is cleaned after each pipeline job. This directory is used by tasks such as .NET Core CLI task to hold temporary items like test results before they are published. |
Agent.ToolsDirectory |
The directory used by tasks such as Node Tool Installer and Use Python Version to switch between multiple versions of a tool.
These tasks will add tools from this directory to PATH so that subsequent build steps can use them.
Learn about managing this directory on a self-hosted agent. |
Agent.WorkFolder |
The working directory for this agent.
For example: c:\agent_work .
|
Build variables (TFS 2018)
Variable | Description |
---|---|
Build.ArtifactStagingDirectory | The local path on the agent where any artifacts are copied to before being pushed to their destination.
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
Build.BuildId | The ID of the record for the completed build. |
Build.BuildNumber | The name of the completed build. You can specify the build number format that generates this value in the pipeline options.
A typical use of this variable is to make it part of the label format, which you specify on the repository tab. Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail.
|
Build.BuildUri | The URI for the build. For example: vstfs:///Build/Build/1430 .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.BinariesDirectory | The local path on the agent you can use as an output folder for compiled binaries.
By default, new build pipelines are not set up to clean this directory. You can define your build to clean it up on the Repository tab. For example: c:\agent_work\1\b .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.DefinitionName | The name of the build pipeline.
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.DefinitionVersion | The version of the build pipeline. |
Build.QueuedBy | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.QueuedById | See "How are the identity variables set?". |
Build.Reason | The event that caused the build to run.
|
Build.Repository.Clean | The value you've selected for Clean in the source repository settings.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.LocalPath |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.SourcesDirectory. |
Build.Repository.Name | The name of the repository.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.Provider | The type of repository you selected.
|
Build.Repository.Tfvc.Workspace | Defined if your repository is Team Foundation Version Control. The name of the TFVC workspace used by the build agent.
For example, if the Agent.BuildDirectory is c:\agent_work\12 and the Agent.Id is 8 , the workspace name could be: ws_12_8
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.Uri | The URL for the repository. For example:
|
Build.RequestedFor | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.RequestedForEmail | See "How are the identity variables set?". |
Build.RequestedForId | See "How are the identity variables set?". |
Build.SourceBranch | The branch the build was queued for. Some examples:
/ ) are replaced with underscore characters _ ).
Note: In TFVC, if you are running a gated check-in build or manually building a shelveset, you cannot use this variable in your build number format. |
Build.SourceBranchName | The name of the branch the build was queued for.
|
Build.SourcesDirectory |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.Repository.LocalPath. |
Build.SourceVersion | The latest version control change that is included in this build. This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.SourceVersionMessage | The comment of the commit or changeset. We truncate the message to the first line or 200 characters, whichever is shorter.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. Note: This variable is available in TFS 2015.4. |
Build.StagingDirectory |
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
Build.Repository.Git.SubmoduleCheckout | The value you've selected for Checkout submodules on the repository tab.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.SourceTfvcShelveset | Defined if your repository is Team Foundation Version Control.
If you are running a gated build or a shelveset build, this is set to the name of the shelveset you are building. Note: This variable yields a value that is invalid for build use in a build number format. |
Common.TestResultsDirectory | The local path on the agent where the test results are created. For example: c:\agent_work\1\TestResults
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System variables (TFS 2018)
Variable | Description |
---|---|
System.AccessToken | Use the OAuth token to access the REST API.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System.CollectionId | The GUID of the TFS collection or Azure DevOps organization |
System.DefaultWorkingDirectory |
The local path on the agent where your source code files are downloaded. For example: |
System.DefinitionId | The ID of the build pipeline. |
System.HostType | Set to build if the pipeline is a build or release if the pipeline is a release. |
System.PullRequest.IsFork | If the pull request is from a fork of the repository, this variable is set to True .
Otherwise, it is set to False . Available in TFS 2018.2. |
System.PullRequest.PullRequestId | The ID of the pull request that caused this build. For example: 17 . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy.) |
System.PullRequest.SourceBranch | The branch that is being reviewed in a pull request. For example: refs/heads/users/raisa/new-feature . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy.) |
System.PullRequest.SourceRepositoryURI | The URL to the repo that contains the pull request. For example: http://our-server:8080/tfs/DefaultCollection/_git/OurProject . (This variable is initialized only if the build ran because of a Azure Repos Git PR affected by a branch policy.) |
System.PullRequest.TargetBranch | The branch that is the target of a pull request. For example: refs/heads/master . This variable is initialized only if the build ran because of a Git PR affected by a branch policy. |
System.TeamFoundationCollectionUri | The URI of the team foundation collection. For example: http://our-server:8080/tfs/DefaultCollection/ .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System.TeamProject | The name of the project that contains this build. |
System.TeamProjectId | The ID of the project that this build belongs to. |
TF_BUILD | Set to True if the script is being run by a build task.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Agent variables (TFS 2017)
Note
You can use agent variables as environment variables in your scripts and as parameters in your build tasks. You cannot use them to customize the build number or to apply a version control label or tag.
Variable | Description |
---|---|
Agent.BuildDirectory |
The local path on the agent where all folders for a given build pipeline are created. For example: |
Agent.ComputerName | The name of the machine on which the agent is installed. |
Agent.HomeDirectory | The directory the agent is installed into. This contains the agent software. For example: c:\agent . |
Agent.Id | The ID of the agent. |
Agent.JobStatus | The status of the build.
The environment variable should be referenced as |
Agent.Name |
The name of the agent that is registered with the pool. This name is specified by you. See agents. |
Agent.WorkFolder |
The working directory for this agent.
For example: c:\agent_work .
|
Build variables (TFS 2017)
Variable | Description |
---|---|
Build.ArtifactStagingDirectory | The local path on the agent where any artifacts are copied to before being pushed to their destination.
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
Build.BuildId | The ID of the record for the completed build. |
Build.BuildNumber | The name of the completed build. You can specify the build number format that generates this value in the pipeline options.
A typical use of this variable is to make it part of the label format, which you specify on the repository tab. Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail.
|
Build.BuildUri | The URI for the build. For example: vstfs:///Build/Build/1430 .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.BinariesDirectory | The local path on the agent you can use as an output folder for compiled binaries.
By default, new build pipelines are not set up to clean this directory. You can define your build to clean it up on the Repository tab. For example: c:\agent_work\1\b .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.DefinitionName | The name of the build pipeline.
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.DefinitionVersion | The version of the build pipeline. |
Build.QueuedBy | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.QueuedById | See "How are the identity variables set?". |
Build.Reason | The event that caused the build to run. Available in TFS 2017.3.
|
Build.Repository.Clean | The value you've selected for Clean in the source repository settings.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.LocalPath |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.SourcesDirectory. |
Build.Repository.Name | The name of the repository.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.Provider | The type of repository you selected.
|
Build.Repository.Tfvc.Workspace | Defined if your repository is Team Foundation Version Control. The name of the TFVC workspace used by the build agent.
For example, if the Agent.BuildDirectory is c:\agent_work\12 and the Agent.Id is 8 , the workspace name could be: ws_12_8
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.Uri | The URL for the repository. For example:
|
Build.RequestedFor | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.RequestedForEmail | See "How are the identity variables set?". |
Build.RequestedForId | See "How are the identity variables set?". |
Build.SourceBranch | The branch the build was queued for. Some examples:
/ ) are replaced with underscore characters _ ).
Note: In TFVC, if you are running a gated check-in build or manually building a shelveset, you cannot use this variable in your build number format. |
Build.SourceBranchName | The name of the branch the build was queued for.
|
Build.SourcesDirectory |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.Repository.LocalPath. |
Build.SourceVersion | The latest version control change that is included in this build. This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.SourceVersionMessage | The comment of the commit or changeset. We truncate the message to the first line or 200 characters, whichever is shorter.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. Note: This variable is available in TFS 2015.4. |
Build.StagingDirectory |
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: |
Build.Repository.Git.SubmoduleCheckout | The value you've selected for Checkout submodules on the repository tab.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.SourceTfvcShelveset | Defined if your repository is Team Foundation Version Control.
If you are running a gated build or a shelveset build, this is set to the name of the shelveset you are building. Note: This variable yields a value that is invalid for build use in a build number format. |
Common.TestResultsDirectory | The local path on the agent where the test results are created. For example: c:\agent_work\1\TestResults
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System variables (TFS 2017)
Variable | Description |
---|---|
System.AccessToken | Use the OAuth token to access the REST API. |
System.CollectionId | The GUID of the TFS collection or Azure DevOps organization |
System.DefaultWorkingDirectory |
The local path on the agent where your source code files are downloaded. For example: |
System.DefinitionId | The ID of the build pipeline. |
System.HostType | Set to build if the pipeline is a build or release if the pipeline is a release. |
System.PullRequest.PullRequestId | The ID of the pull request that caused this build. For example: 17 . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy.) |
System.PullRequest.SourceBranch | The branch that is being reviewed in a pull request. For example: refs/heads/users/raisa/new-feature . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy.) |
System.PullRequest.SourceRepositoryURI | The URL to the repo that contains the pull request. For example: http://our-server:8080/tfs/DefaultCollection/_git/OurProject . (This variable is initialized only if the build ran because of a Azure Repos Git PR affected by a branch policy.) |
System.PullRequest.TargetBranch | The branch that is the target of a pull request. For example: refs/heads/master . This variable is initialized only if the build ran because of a Git PR affected by a branch policy. |
System.TeamFoundationCollectionUri | The URI of the team foundation collection. For example: http://our-server:8080/tfs/DefaultCollection/ .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System.TeamProject | The name of the project that contains this build. |
System.TeamProjectId | The ID of the project that this build belongs to. |
TF_BUILD | Set to True if the script is being run by a build task.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Agent variables (TFS 2015)
Note
You can use agent variables as environment variables in your scripts and as parameters in your build tasks. You cannot use them to customize the build number or to apply a version control label or tag.
Variable | Description |
---|---|
Agent.BuildDirectory |
The local path on the agent where all folders for a given build pipeline are created. For example:
|
Agent.HomeDirectory |
The directory the agent is installed into. This contains the agent software. For example:
|
Agent.Id | The ID of the agent. |
Agent.JobStatus | The status of the build.
Note: The environment variable can be referenced only as |
Agent.MachineName | The name of the machine on which the agent is installed. This variable is available in TFS 2015.4, not in TFS 2015 RTM. |
Agent.Name |
The name of the agent that is registered with the pool. This name is specified by you. See agents. |
Agent.WorkFolder |
The working directory for this agent.
For example: c:\agent_work .
|
Build variables (TFS 2015)
Variable | Description |
---|---|
Build.ArtifactStagingDirectory | The local path on the agent where any artifacts are copied to before being pushed to their destination.
A typical way to use this folder is to publish your build artifacts with the Copy files and Publish build artifacts tasks. See Artifacts in Azure Pipelines. For example:
In TFS 2015.4, Build.ArtifactStagingDirectory and Build.StagingDirectory are interchangeable. This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.BuildId | The ID of the record for the completed build. |
Build.BuildNumber | The name of the completed build. You can specify the build number format that generates this value in the pipeline options.
A typical use of this variable is to make it part of the label format, which you specify on the repository tab. Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail.
|
Build.BuildUri | The URI for the build. For example: vstfs:///Build/Build/1430 .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.BinariesDirectory |
The local path on the agent you can use as an output folder for compiled binaries. Available in TFS 2015.4.
By default, new build pipelines are not set up to clean this directory. You can define your build to clean it up on the Repository tab. For example: C:\TfsData\Agents\Agent-MACHINENAME_work\1\b
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.DefinitionName | The name of the build pipeline.
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.DefinitionVersion | The version of the build pipeline. |
Build.QueuedBy | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.QueuedById | See "How are the identity variables set?". |
Build.Repository.Clean | The value you've selected for Clean in the source repository settings.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.LocalPath |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.SourcesDirectory. |
Build.Repository.Name | The name of the repository.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.Provider | The type of repository you selected.
|
Build.Repository.Tfvc.Workspace | Defined if your repository is Team Foundation Version Control. The name of the TFVC workspace used by the build agent.
For example, if the Agent.BuildDirectory is c:\agent_work\12 and the Agent.Id is 8 , the workspace name could be: ws_12_8
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.Uri | The URL for the repository. For example:
|
Build.RequestedFor | See "How are the identity variables set?".
Note: This value can contain whitespace or other invalid label characters. In these cases, the label format will fail. |
Build.RequestedForId | See "How are the identity variables set?". |
Build.SourceBranch | The branch the build was queued for. Some examples:
/ ) are replaced with underscore characters _ ).
Note: In TFVC, if you are running a gated check-in build or manually building a shelveset, you cannot use this variable in your build number format. |
Build.SourceBranchName | The name of the branch the build was queued for.
|
Build.SourcesDirectory |
The local path on the agent where your source code files are downloaded. For example: This variable is synonymous with Build.Repository.LocalPath. |
Build.SourcesDirectoryHash | Note: This variable is available in TFS 2015 RTM, but not in TFS 2015.4. |
Build.SourceVersion | The latest version control change that is included in this build. This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.SourceVersionMessage | The comment of the commit or changeset. We truncate the message to the first line or 200 characters, whichever is shorter.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. Note: This variable is available in TFS 2015.4. |
Build.StagingDirectory |
TFS 2015 RTM
The local path on the agent you can use as an output folder for compiled binaries. For example: C:\TfsData\Build_work\6c3842c6\staging .
By default, new build pipelines are not set up to clean this directory. You can define your build to clean it up on the Repository tab. TFS 2015.4 The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: C:\TfsData\Agents\Agent-MACHINENAME_work\1\a
This directory is purged before each new build, so you don't have to clean it up yourself. A typical way to use this folder is to publish your build artifacts with the Copy files and Publish build artifacts tasks. See Artifacts in Azure Pipelines. In TFS 2015.4, Build.ArtifactStagingDirectory and Build.StagingDirectory are interchangeable. All versions of TFS 2015 This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.Repository.Git.SubmoduleCheckout | The value you've selected for Checkout submodules on the repository tab.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
Build.SourceTfvcShelveset | Defined if your repository is Team Foundation Version Control.
If you are running a gated build or a shelveset build, this is set to the name of the shelveset you are building. Note: This variable yields a value that is invalid for build use in a build number format. |
Common.TestResultsDirectory | The local path on the agent where the test results are created. For example: c:\agent_work\1\TestResults . Available in TFS 2015.4.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System variables (TFS 2015)
Variable | Description |
---|---|
System.AccessToken | Available in TFS 2015.4. Use the OAuth token to access the REST API.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System.CollectionId | The GUID of the TFS collection or Azure DevOps organization |
System.DefaultWorkingDirectory |
The local path on the agent where your source code files are downloaded. For example: |
System.DefinitionId | The ID of the build pipeline. |
System.HostType | Set to build if the pipeline is a build or release if the pipeline is a release. |
System.PullRequest.PullRequestId | The ID of the pull request that caused this build. For example: 17 . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy.) |
System.PullRequest.SourceBranch | The branch that is being reviewed in a pull request. For example: refs/heads/users/raisa/new-feature . (This variable is initialized only if the build ran because of a Git PR affected by a branch policy.) |
System.PullRequest.SourceRepositoryURI | The URL to the repo that contains the pull request. For example: http://our-server:8080/tfs/DefaultCollection/_git/OurProject . (This variable is initialized only if the build ran because of a Azure Repos Git PR affected by a branch policy.) |
System.PullRequest.TargetBranch | The branch that is the target of a pull request. For example: refs/heads/master . This variable is initialized only if the build ran because of a Git PR affected by a branch policy. |
System.TeamFoundationCollectionUri | The URI of the team foundation collection. For example: http://our-server:8080/tfs/DefaultCollection/ .
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
System.TeamProject | The name of the project that contains this build. |
System.TeamProjectId | The ID of the project that this build belongs to. |
TF_BUILD | Set to True if the script is being run by a build task.
This variable is agent-scoped. It can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag. |
How are the identity variables set?
The value depends on what caused the build.
If the build is triggered... | Then the Build.QueuedBy and Build.QueuedById values are based on... | Then the Build.RequestedFor and Build.RequestedForId values are based on... |
---|---|---|
In Git or TFVC by the Continuous integration (CI) triggers | The system identity, for example: [DefaultCollection]\Project Collection Service Accounts |
The person who pushed or checked in the changes. |
In Git or by a branch policy build. | The system identity, for example: [DefaultCollection]\Project Collection Service Accounts |
The person who checked in the changes. |
In TFVC by a gated check-in trigger | The person who checked in the changes. | The person who checked in the changes. |
In Git or TFVC by the Scheduled triggers | The system identity, for example: [DefaultCollection]\Project Collection Service Accounts |
The system identity, for example: [DefaultCollection]\Project Collection Service Accounts |
Because you clicked the Queue build button | You | You |