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