0
votes

I am trying to update my specific Build's Pipeline variable to auto increment the version number variable for between each Build that is generated. And I saw the documentation on using $(Rev:.r), but this is not what I want.

Please see the below code, I've tried using ##vso[task.setvariable variable=myVar;]$myNewVar approach, but I think this only persists within the build and not actually update the build's pipeline variable as I had expected.

$vstsCurrentVersionNumber = $env:VersionNumber
$currentVersionNumber = $vstsCurrentVersionNumber.Split(".")
$revisionNumber = $currentVersionNumber[3]
$newRevisionNumber = [int]$revisionNumber + 1
$newVersionNumber = $currentVersionNumber[0] + "." + 
$currentVersionNumber[1] + "." + $currentVersionNumber[2] + "." + 
$newRevisionNumber
$env:VersionNumber = $newVersionNumber

Write-Host "##vso[task.setvariable variable=VersionNumber;]$newVersionNumber"
Write-Output "Current Version Number is '$vstsCurrentVersionNumber' with 
Revision Number '$revisionNumber'"
Write-Output "Next Version Number will be '$newVersionNumber' with 
Revision Number '$newRevisionNumber'"
Write-Output "Current VSTS Version Number: '$vstsCurrentVersionNumber'"
Write-Output "New VSTS Version Number: '$env:VersionNumber'"

I am expecting the Build's Pipeline Variable to be updated as per the Powershell script I wrote. So for instance, before running the build, I would expect to see VersionNumber to be 2.0.0.7 and then after running the build successfully I'd expect to see VersionNumber to be 2.0.0.8.

However when I run this script the Build's Pipeline Variable remains 2.0.0.7

1
See here...Peter Schneider
@PeterSchneider This is great if I'm using BuildNumber but I'd like to modify my specific Build's Pipeline variables. Any ideas?ccaunca

1 Answers

0
votes

Is there a way to have this update the Build's Pipeline variables?

The short answer is Yes.

When we change the value of variables VersionNumber with powershell, we could use this new value in the build.

But if you still want to change the value in Variables on the web portal, We could not change the value on the UI directly, we need use the REST API (Definitions - Update) to update the value of the build pipeline definition variable from a build task.

There is a very similar thread, you can check the answer for the details:

How to modify Azure DevOps release definition variable from a release task?

Note:Change the API to the build definitions:

PUT https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=5.0

Hope this helps.