Skip to content

Commit c0ea19b

Browse files
committed
draft
1 parent 8075581 commit c0ea19b

File tree

1 file changed

+37
-43
lines changed

1 file changed

+37
-43
lines changed

docs/pipelines/process/run-number.md

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,71 @@ title: Configure 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/11/2025
77
monikerRange: "<=azure-devops"
88
---
99

1010
# Run and build numbers
1111

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

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.
14+
Azure Pipelines assigns a unique run number, also called a build number, to identify each execution of a pipeline or build. This article explains the structure of these numbers and how you can customize them to be more meaningful for your team.
1515

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-
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.
16+
If you don't specify a build name in YAML pipelines, or you leave the **Build number format** field blank in Classic pipelines, each run gets a unique integer as its name. You can use a combination of naming patterns, tokens, and variables to give runs more useful names.
1917

2018
::: moniker range=">=azure-devops-2020"
2119

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.
20+
## Customize the name property
21+
22+
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 by using the `name` property at the [pipeline](/azure/devops/pipelines/yaml-schema/pipeline) level. The `name` property isn't supported in templates or stages.
2323

24-
The following code sets a custom run number format like `project_def_main_202408281`:
24+
The following YAML pipeline example sets a custom run number format like **project_def_main_202408281**:
2525

2626
```yaml
2727
name: $(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd).$(Rev:r)
2828

2929
steps:
30-
- script: echo '$(Build.BuildNumber)'
30+
- script: echo '$(Build.BuildNumber)'
3131
```
3232
3333
::: moniker-end
3434
35-
## Run number
35+
## Run numbers
3636
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.
37+
The default value for an Azure Pipelines run number is `$(Date:yyyyMMdd).$(Rev:r)`. The `$(Rev:r)` is a special variable that works only in the build number field. When a build completes, if nothing else in the build number changed, the `Rev` integer value increases by one.
3838

3939
`$(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.
4040

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`.
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**.
4442

45-
## Example
43+
`$(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**.
4644

47-
Consider the following data for a build run:
45+
For example, if you specify the build number format `$(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd).$(Rev:r)`, the second run on May 6, 2024 is named **Fabrikam_CIBuild_main_20240506.2**.
4846

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.
47+
The build number tokens resolve as follows:
5648

57-
If you specify the following build number format, the second run on May 6, 2024 is named **Fabrikam_CIBuild_main_20240506.2**.
58-
59-
```yaml
60-
$(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd).$(Rev:r)
61-
```
49+
- Project name: **Fabrikam**
50+
- Build definition name: **CIBuild**
51+
- Branch: **main**
52+
- Build/run ID: **752**
53+
- Date: **May 6, 2024**
54+
- Run number for that day: **2**
6255

63-
## Tokens
56+
### 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 | 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 | 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
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 build number, you can't use `$(Build.BuildId)`, `$(Build.BuildUri)`, or `$(Build.BuildNumber)` tokens, because their values aren't set at the time pipeline expressions are evaluated.
9285

93-
## Variables
86+
### Variables
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 build 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)