Udostępnij za pośrednictwem


Configure run or build numbers

TFS 2017 | 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.

You can customize how your pipeline runs are numbered. The default value for run number is $(Date:yyyyMMdd).$(Rev:r).

YAML builds are not available on TFS 2017.

Example

At the time a run is started:

  • Project name: Fabrikam

  • Pipeline name: CIBuild

  • Branch: master

  • Build ID/Run ID: 752

  • Date: May 5, 2019.

  • Time: 9:07:03 PM.

  • One run completed earlier today.

If you specify this build number format:

$(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)

Then the second run on this day would be named: Fabrikam_CIBuild_master_20190505.2

Tokens

The following table shows how each token is resolved based on the previous example. You can use these tokens only to define a run number; they don't work anywhere else in your pipeline.

Token Example replacement value
$(Build.DefinitionName) CIBuild

Note: The pipeline name must not contain invalid or whitespace characters.
$(Build.BuildId) 752

$(Build.BuildId) is an internal immutable ID that is also referred to as the Run ID. It is unique across the organization.
$(DayOfMonth) 5
$(DayOfYear) 217
$(Hours) 21
$(Minutes) 7
$(Month) 8
$(Rev:r) 2 (The third run will be 3, and so on.)

Use $(Rev:r) to ensure that every completed build has a unique name. When a build starts, if nothing else in the build number has changed, the Rev integer value is incremented by one.

If you want to show prefix zeros in the number, you can add additional 'r' characters. For example, specify $(Rev:rr) if you want the Rev number to begin with 01, 02, and so on. If you use a zero-padded Rev as part of a version numbering scheme, note that some pipeline tasks or popular tools, like NuGet packages, remove the leading zeros, which causes a version number mismatch in the artifacts that are produced.
$(Date:yyyyMMdd) 20090824

You can specify other date formats such as $(Date:MMddyy)
$(Seconds) 3
$(SourceBranchName) master
$(TeamProject) Fabrikam
$(Year:yy) 09
$(Year:yyyy) 2009

Variables

You can also use user-defined and predefined variables that have a scope of "All" in your number. For example, if you've defined My.Variable, you could specify the following number format:

$(Build.DefinitionName)_$(Build.DefinitionVersion)_$(Build.RequestedFor)_$(Build.BuildId)_$(My.Variable)

The first four variables are predefined. My.Variable is defined by you on the variables tab.

Expressions

If you use an expression to set the build number, you can't use some tokens because their values aren't set at the time expressions are evaluated. These tokens include $(Build.BuildId), $(Build.BuildURL), and $(Build.BuildNumber).

FAQ

How large can a run number be?

Runs may be up to 255 characters.

In what time zone are the build number time values expressed?

The time zone is the same as the time zone of the operating system of the machine where you are running your application tier server.