Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update BuildNumber using PowerShell

I would like to update the Build.BuildNumber variable from a PowerShell script as a build step.

I've tried:

Write-Host "##vso[task.setvariable variable=BUILD_BUILDNUMBER]1.2.3.4"

and

Write-Host "##vso[task.setvariable variable=Build.BuildNumber]1.2.3.4"

This has not worked.

like image 287
JL. Avatar asked May 05 '16 09:05

JL.


People also ask

How to give build number in azure DevOps?

Build numbers in Azure DevOps In Azure DevOps, build numbers may be in a format that doesn't represent a valid SemVer number. For example, Microsoft's Build Number format documentation gives an example: $(TeamProject)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.

How do I customize my build number?

Go to the General Settings of the build configuration. Click the orange Show advanced options. Set the Build counter to your desired value. Set the Build number format to %build.


1 Answers

You'd need to use the Update Build Number function:

Write-Host "##vso[build.updatebuildnumber]1.0.0.$($env:Build_BuildId)"

BuildNumber is a special case. Other variables can be overwritten using the setvariable macro you mentioned.

It will overwrite the actual build number as well so after your statement you Build Number in the Builds overview will reflect the new number.

There are two tasks which may help you out here. My own Variable Toolbox and the Variables Task pack. With those you can set variables to a specific value and while my own task will auto-correct the command to set the buildnumber when that variable is passed as output variable. The Task pack has a special task to set the build number.

like image 67
jessehouwing Avatar answered Sep 20 '22 19:09

jessehouwing