Explore Courses Blog Tutorials Interview Questions
0 votes
in Azure by (45.3k points)

I have a Microsoft Visual Studio Team Foundation Server (Version 15.117.26714.0) with predefined variable $(ProjectBuildNumber).

Is there any way to increment, during build process, value of variable with minor build number by +1?

$(ProjectBuildNumber)  =   663

So, that on next build it will be:

$(ProjectBuildNumber)  =   664

enter image description here

enter image description here

1 Answer

0 votes
by (16.8k points)

You can't reference variables in the build number of the Build Definition. But what you can do is override the build number in the build itself. You can either use a magic log command or use my VSTS Variables Task to set the Build.BuildNumber in the build itself. The Variables Task does expand variable references. You could probably just set the value to the current value to get it expanded.

enter image description here

To issue the log command yourself use a batch script, PowerShell or bash to output the following specific string to the console:

##vso[build.updatebuildnumber]build number

Update build number for current build. Example:


Minimum agent version: 1.88


An alternative option is to use the $(Rev) option:

Build.BuildNumber = 1.1.$(Rev:.r)  

That will automatically increase the variable each time the build runs.

To update a variable in a Build Definition use yet another extension:

enter image description here

These things combined should be able to get what you want.

Browse Categories