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.
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:.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With