Please help me to get auto incremented revision number for the pipeline build task in Azure.
Let's say there is major.minor.patch.revision number. major.minor.patch is set in the version file that is stored in the source control. This allows to define software version by the source code maintainer and do not change the build task definition (or its parameter). I'd like to avoid version parameter value update before new version is going to be built.
However I'd like to get revision increased automatically each time when version builds. To make it possible to have major.minor.patch the same.
Version file is a plain text file with major.minor.patch content. I have powershell script task in the build pipeline. It read version file and store as build variable like below:
$fv = Get-Content versionFile
$buildNumber = $env:BUILD_BUILDNUMBER
if ($buildNumber -eq $null)
{
$buildIncrementalNumber = 0
}
else
{
$splitted = $buildNumber.Split('.')
$buildIncrementalNumber = $splitted[$splitted.Length - 1]
}
Write-Host ("##vso[task.setvariable variable=versionFromFile]$fv.$buildIncrementalNumber")
Write-Host ("from file $fv incremental .$buildIncrementalNumber")
Write-Host ("##vso[task.setvariable variable=build.updatebuildnumber]$fv.$buildIncrementalNumber")
As you can see it read from versionFile
and takes .N
part from the BUILDNUMBER variable to get revision value. And it stores result value to the versionFromFile
variable.
And I'd like to get latest version to be updated for each build automatically for the certain project. Just not to update version source file for each build that is started for each commit to the master branch.
I've tried to use build number format however the problem is that $(Rev:.r)
is reseted if main part of the Build number format
was changed. This means that for number format $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
Rev is started from zero each day.
$(BuildId)
is an unique value that can not be cleared (started from zero)
I've tried to use the versionFromFile
variable in the build number format string but seems that build number is calculated when pipeline is started and there is no way to use custom (script) variable value in the build number.
I think to create one more file, like revisionFile
and store revision value in this file. However then I will need to update revisionFile
on each build and commit.
Is there any other option to get build auto incremented count for the project? I've met a sample how to update build pipeline variable from the powershell script but it is linked with pipeline so having two build pipelines will produce the same value for (probably) different version.
PS There is a possibility to update build number by outputing "##vso[build.updatebuildnumber]1.2.3.4" to the log during the build but Rev
value is calculated before any task have a chance to update build number.
There are Git and Tfs projects so it would be nice to have the same solution for both types of the source control.
versionFile
(each build will update this file) so it will be hard to distinguish between the version number changes and the ordinary build. That is why I suggested to use dedicated files – oleksa