Update Variable in TeamCity powershell script

Posted by Jake Rote on Programmers See other posts from Programmers or by Jake Rote
Published on 2014-06-11T12:41:28Z Indexed on 2014/06/11 15:40 UTC
Read the original article Hit count: 296

Filed under:

I am try to update an enviroment variable in teamcity using powershell code. But it does not update the value of the variable. How can i do this? My current code is (It gets the currentBuildNumber fine:

$currentBuildNumber = "%env.currentBuildNumber%"
$newBuildNumber = ""
Write-Output $currentBuildNumber
If ($currentBuildNumber.StartsWith("%MajorVersion%") -eq "True")
{
 $parts = $currentBuildNumber.Split(".")
 $parts[2] = ([int]::Parse($parts[2]) + 1) + ""
 $newBuildNumber = $parts -join "."
}
Else
{
 $newBuildNumber = '%MajorVersion%.1'
}

//What I have tried
$env:currentBuildNumber = $newBuildNumber
Write-Host "##teamcity[env.currentBuildNumber '$newBuildNumber']"
Write-Host "##teamcity[setParameter name='currentBuildNumber' value='$newBuildNumber']"

© Programmers or respective owner

Related posts about powershell