We had set up my TFS CI Build, and we're managing one variable for our purposes to maintaining versioning, We want to update after every success build, any idea how to do so?
I had written PowerShell script
param([Int32]$currentPatchVersion)
Write-Host "Current patch version "$currentPatchVersion
$NewVersion=$currentPatchVersion + 1
Write-Host "New patch version "$NewVersion
Write-Host ("##vso[task.setvariable variable=PackageVersion.Patch;]$NewVersion")
but it just applies on the fly.
I want's to apply it on setting permanently.
"##vso[task.setvariable variable=PackageVersion.Patch;]$NewVersion"
just set the variable value in the build process, it doesn't set the value in the build definition level. If you want to update the variable value in the build definition permanently, you can call the Rest API to set the value of the variables in the definition. Refer to following section for details:Create a
"testvariable"
as example:Create a Power Shell script with following code and upload it into source control:
This script will get the current build definition and update the value of
"testvariable"
to"1.0.0.1"
. You need to enable alternative credential.And then you can add a "PowerShell Script" task in your build definition to run this script.