liorda
liorda

Reputation: 1572

TFS 2015 Build definition - override Build number with variables

We use a nice $(date:yyyy.MM.dd)$(rev:.r) build number format in our day-to-day agile sprints. However, the release must be numbered with a simpler 1.0.0.rev schema.

Ideally, I would like to give the build number as a variable, which would be automatically expanded in the "queue build" dialog, where it would be possible to be overriden. How can it be done?

I tried moving the $(date:yyyy.MM.dd)$(rev:.r) format to a variable, and use that variable in the general tab, and got error 400.

Upvotes: 1

Views: 6179

Answers (2)

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51083

You could directly use Environment variables such as Build.BuildNumber /BUILD_BUILDNUMBER

Using this just equals to the name of the completed build. You can specify the build number format that generates this value on the General tab.

If you just want to generate custom build numbers like 1.0.0.rev schema in TFS Build vNext. You can take a look at below blogs:

Upvotes: 2

Antebios
Antebios

Reputation: 1781

This is very simple.

1) Just create a Powershell script like this

$FinalVersion=Some-Function-To-Calculate-Version
$BuildDefName = $Env:BUILD_DEFINITIONNAME
Write-Host "##vso[build.updatebuildnumber]$($BuildDefName)-$($FinalVersion)"

2) In your vNext build definition, for "Build number format" just set it to anything. It doesn't matter because the Build Number will be overwritten.

3) In the same vNext build definition steps, add the first step as a Powershell step, and set your script from step 1 to be executed. You can later customize if you want to pass variables in order to calculate your build number.

4) Queue your build and see the results.

Upvotes: 2

Related Questions