Skip to content

Commit 8238693

Browse files
committed
Merged main into live
2 parents 4293e02 + d4fc096 commit 8238693

File tree

1 file changed

+39
-45
lines changed

1 file changed

+39
-45
lines changed
Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,73 @@
11
---
2-
title: Configure run and build numbers
2+
title: Run and build numbers
33
description: Learn about Azure Pipelines run numbers and build numbers and how you can configure them in your pipelines.
44
ms.topic: conceptual
55
ms.assetid: 7C469647-117D-4867-B094-8BC811C0003E
6-
ms.date: 07/01/2024
6+
ms.date: 08/12/2025
77
monikerRange: "<=azure-devops"
8+
#customer intent: As an Azure Pipelines customer, I want to understand the composition of run numbers so I can customize them to be more meaningful and useful for my team.
89
---
910

1011
# Run and build numbers
1112

1213
[!INCLUDE [version-lt-eq-azure-devops](../../includes/version-lt-eq-azure-devops.md)]
1314

14-
Azure Pipelines assigns a unique run number (also called a build number) to each pipeline execution. You can customize these numbers to make them more meaningful for your team, using variables, tokens, and naming patterns.
15+
A unique run number or build number identifies each execution of an Azure Pipelines pipeline or build. This article explains the structure of this number and how you can customize it to be more useful or meaningful for your team.
1516

16-
The run number is used to identify a specific execution of a pipeline or build. The build number is synonymous with the run number.
17+
If you don't specify a build name in YAML pipelines, or you leave the **Name** or **Build number format** field blank in Classic pipelines, each run gets a unique integer as its name. Build names can use other characters, tokens, and variables. You can customize run and build numbers by using naming patterns, special tokens, and predefined or user-defined variables.
1718

18-
If you don't specify a build name in YAML pipelines, or you leave the **Name** field blank in Classic pipelines, your run gets a unique integer as its name. You can give runs more useful names that are meaningful to your team. You can use a combination of tokens, variables, and underscore characters in build names.
19+
## Build number configuration
1920

20-
::: moniker range=">=azure-devops-2020"
21-
22-
You can only customize the run number at the root level of your pipeline using the `name` property. Set the `name` property at the [pipeline](/azure/devops/pipelines/yaml-schema/pipeline) level. The `name` property isn't supported in templates or stages.
21+
In Classic pipelines, you can customize the **Build number format** under **Options** in the pipeline definition. In YAML pipelines, you can customize the run number format by using the `name` property at the [pipeline](/azure/devops/pipelines/yaml-schema/pipeline) level of the YAML file. The `name` property isn't supported in templates or stages.
2322

24-
The following code sets a custom run number format like `project_def_main_202408281`:
23+
The following example sets a custom run number format that produces a build number like **MyProject_MyBuild_main_20240828.1**.
2524

2625
```yaml
2726
name: $(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd).$(Rev:r)
2827

2928
steps:
30-
- script: echo '$(Build.BuildNumber)'
29+
- script: echo '$(Build.BuildNumber)'
3130
```
3231
33-
::: moniker-end
34-
3532
## Run number
3633
37-
The default value for a run number in Azure Pipelines is `$(Date:yyyyMMdd).$(Rev:r)`. `$(Rev:r)` is a special variable format that only works in the build number field. When a build completes, if nothing else in the build number changed, the `Rev` integer value increases by one.
34+
The default value for an Azure Pipelines run number is `$(Date:yyyyMMdd).$(Rev:r)`. The `$(Rev:r)` revision variable works only in a build number field. When a build completes, if nothing else in the build number changes, the `Rev` integer value increases by one.
3835

3936
`$(Rev:r)` resets to `1` when any other part of the build number changes. For example, if you configure your build number format as `$(Build.DefinitionName)_$(Date:yyyyMMdd).$(Rev:r)`, the build number resets when the date changes.
4037

41-
If the previous build number was `MyBuild_20230621.1`, the next build number that day is `MyBuild_20230621.2`. The first build number the next day is `MyBuild_20230622.1`.
42-
43-
`$(Rev:r)` also resets to `1` if you change the build number to indicate a version change. For example, if your build format is `1.0.$(Rev:r)` and your last build number was `1.0.3`, if you change the build number to `1.1.$(Rev:r)`, the next build number is `1.1.1`.
38+
If the previous build number was **MyBuild_20230621.1**, the next build number that day is **MyBuild_20230621.2**. The first build number the next day is **MyBuild_20230622.1**.
4439

45-
## Example
40+
`$(Rev:r)` also resets to `1` if you change the version. If your build format is `1.0.$(Rev:r)` and your last build number was **1.0.3**, if you change the version to `1.1.$(Rev:r)`, the next build number is **1.1.1**.
4641

47-
Consider the following data for a build run:
48-
49-
- Project name: Fabrikam
50-
- Pipeline name: CIBuild
51-
- Branch: main
52-
- Build ID/Run ID: 752
53-
- Date: May 6, 2024
54-
- Time: 9:07:03 PM
55-
- One run completed earlier today.
56-
57-
If you specify the following build number format, the second run on May 6, 2024 is named **Fabrikam_CIBuild_main_20240506.2**.
42+
The following build number format produces the name **Fabrikam_CIBuild_main_20240506.2** for the second run on May 6, 2024.
5843

5944
```yaml
60-
$(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd).$(Rev:r)
45+
name: $(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd).$(Rev:r)
6146
```
6247

63-
## Tokens
48+
The build number tokens resolve as follows:
49+
50+
- Project name: **Fabrikam**
51+
- Build definition name: **CIBuild**
52+
- Branch: **main**
53+
- Date: **May 6, 2024**
54+
- Run number for that day: **2**
55+
56+
### Run number tokens
6457

65-
The following table shows how each token resolves, based on the previous example. You can use these tokens only to define run numbers. They don't work anywhere else in a pipeline.
58+
The following table shows how run number tokens resolve. You can use these tokens only to define run numbers. They don't work anywhere else in a pipeline.
6659

6760
| Token | Example value | Notes |
6861
| ----- | -------------- | ----------- |
69-
| `$(Build.DefinitionName)` | CIBuild | The pipeline name can't contain invalid or whitespace characters.|
70-
| `$(Build.BuildId)` | 752 | `$(Build.BuildId)` is an internal, immutable ID, also called the Run ID, that is unique across the Azure DevOps organization.|
62+
| `$(Build.DefinitionName)` | CIBuild | A build name, which can't contain invalid or whitespace characters.|
63+
| `$(Build.BuildId)` | 752 | An internal, immutable ID, also called the `Run ID`, that's unique in the Azure DevOps organization.|
64+
| `$(Date:yyyyMMdd)` | 20240506 | A date format. You can also specify other date formats, such as `$(Date:MMddyy)`. |
7165
| `$(DayOfMonth)` | 6 ||
7266
| `$(DayOfYear)` | 126 ||
7367
| `$(Hours)` | 21 ||
7468
| `$(Minutes)` | 7 ||
7569
| `$(Month)` | 5 ||
76-
| `$(Rev:r)` | 2 | The third daily run is `3`, and so on. Use `$(Rev:r)` to ensure that every completed build has a unique name. |
77-
| `$(Date:yyyyMMdd)` | 20240506 | You can specify other date formats such as `$(Date:MMddyy)`. |
70+
| `$(Rev:r)` | 2 | Position in the number of runs that day. Use `$(Rev:r)` to ensure that every completed build has a unique name. |
7871
| `$(Seconds)` | 3 ||
7972
| `$(SourceBranchName)` | main ||
8073
| `$(TeamProject)` | Fabrikam ||
@@ -84,21 +77,21 @@ The following table shows how each token resolves, based on the previous example
8477
>[!IMPORTANT]
8578
>If you want to show prefix zeros in the run number, you can add more `r` characters to the `Rev` token. For example, specify `$(Rev:rr)` if you want the `Rev` number to begin with `01`, `02`, and so on.
8679
>
87-
>If you use a zero-padded `Rev` as part of a version numbering scheme, some pipeline tasks or popular tools, like NuGet packages, remove the leading zeros. This behavior causes a version number mismatch in the artifacts that are produced.
80+
>However, if you use a zero-padded `Rev` as part of a version numbering scheme, some pipeline tasks or popular tools like NuGet packages remove the leading zeros. This behavior causes a version number mismatch in the artifacts that the build produces.
8881

89-
## Expressions
82+
### Expressions in run numbers
9083

91-
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)`.
84+
If you use an expression to set the run number, you can't use the `$(Build.BuildId)`, `$(Build.BuildUri)`, or `$(Build.BuildNumber)` tokens, because their values aren't set yet at the time pipeline expressions are evaluated.
9285

93-
## Variables
86+
### Variables in run numbers
9487

95-
You can use user-defined and predefined variables in your build number. For example, if you define `My.Variable`, you can specify the following number format:
88+
You can use both predefined and user-defined variables in your run number. For example, if you define `My.Variable`, you can specify the following number format. The first four variables are predefined.
9689

9790
```yaml
9891
$(Build.DefinitionName)_$(Build.DefinitionVersion)_$(Build.RequestedFor)_$(Build.BuildId)_$(My.Variable)
9992
```
10093

101-
In the preceding example, the first four variables are predefined. For information on how to define user variables, see [Set variables in pipelines](variables.md#set-variables-in-pipeline).
94+
For more information about predefined variables, see [Use predefined variables](../build/variables.md). For information on how to define user variables, see [Define variables](variables.md).
10295

10396
## FAQ
10497

@@ -118,15 +111,15 @@ The time zone is UTC.
118111

119112
::: moniker range="<azure-devops"
120113

121-
The time zone is the same as the time zone of the operating system of the machine that runs your application tier server.
114+
The time zone is the same as the operating system of the machine that runs your application tier server.
122115

123116
::: moniker-end
124117

125118
::: moniker range=">=azure-devops-2020"
126119

127120
### How can I set the build number dynamically with conditions?
128121

129-
You can use variables as part of your run number. In the following example, the variable `why` is used as part of the run number, and its value changes depending on the `Build.Reason`.
122+
You can use variables as part of your run number. In the following example, the variable `why` is set as part of the run number, and its value changes depending on the `Build.Reason`.
130123

131124
```yaml
132125
variables:
@@ -151,7 +144,7 @@ steps:
151144

152145
### How can I reference the run number variable within a script?
153146

154-
You can reference the run number directly as `$(Build.BuildNumber)` in your scripts, or create a custom variable that includes it. For example:
147+
You can reference the run number directly as `$(Build.BuildNumber)` in your scripts, or create a custom variable that includes the number. For example:
155148

156149
```yaml
157150
# Set MyRunNumber
@@ -168,4 +161,5 @@ steps:
168161
<!-- ENDSECTION -->
169162
## Related content
170163

171-
[Define variables](variables.md)
164+
- [Define variables](variables.md)
165+
- [Use predefined variables](../build/variables.md)

0 commit comments

Comments
 (0)