18

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.

1 Answer 1

36

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.

Sign up to request clarification or add additional context in comments.

3 Comments

This throws an exception: Unable to process logging event:##vso[build.updatebuildnumber]. Could it be .88 of the agent is required? I'm using .83?
That or it only works in ps custom tasks, not random scripts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.