June 21, 2019 · Azure DevOps · 1 min read · apurvghai · Yaml
This article will help you understand how to customize your build number for CD/CI pipeline. There are two ways either by using predefined variables or custom variables.
Here is an official documentation on using these variables.
My favorite format is Date.Month.Year.RunningNumber
.
$(date:dd)$(date:.MM)$(date:.yyyy)$(rev:.r)
Now if you notice I have used periods (.) before each format, this is to make sure you can output the number as 21.06.2019.X
. You can also use a 4 digit revision number by adding multiple variables r
which would then look like this $(rev:.rrrr)
. The advantage in this approach is that, you don’t have to worry about the incremental build value. DevOps will take care of incrementing revision for you. This may or may not be ideal technique in your business scenario. For further customization and custom logic, let’s look into using custom variables.
To define custom variables, you need to edit your pipeline and go to variables tab. See the image below:
Once you have a variable defined, you can either use powershell or yaml to consume those variables. Let’s take an example of inline powershell script, where you want to define a build number.
# TODO:// Write your logic for generating the build numbers
$CustomNumber = "$Day.$Month.$Year"
Write-Host "##vso[task.setvariable variable=CustomVariable]$CustomNumber"
Here is an example of powershell task added to a pipeline.
Develop your docs site with docfx
Dec 21, 20 by apurvghai
Versioning your assemblies through build pipelines
Jun 21, 19 by apurvghai
Customize your build number
Jun 21, 19 by apurvghai