How to set build number in Teamcity?

I am trying to set the build number format in Teamcity using Powershell (sort of like in this Octopus Deploy post).

However, I don’t know if Teamcity’s behavior with service messages has changed since then or if I am doing it wrong because it doesn’t work.

I have the following Powershell script as the first step in my build configuration:

$buildCounter = "%build.counter%" 
$buildConfig = "%system.buildconfig%"
$version = "%system.majorMinorVersion%"

$branch = "%vcsroot.branch%"

if ($branch.Contains("/")) 
{
    $branch = $branch.substring($branch.lastIndexOf("/")).trim("/")
}

$buildNumber = "${version}.${buildCounter}-${branch}"

Write-Host "##teamcity[buildNumber '$buildNumber']"

(I also tried $branch = "%teamcity.build.branch%"on line 5)

, , if , , , Octopus Deploy, , $branch %vcsroot.branch%, , , Teamcity ##teamcity[buildNumber '$buildNumber']. , /, , refs/head/master, master.

?

+4
2

, script :

Write-Host "##teamcity[buildNumber '${buildNumber}']"

: script, script TeamCity ( TeamCity% -references).

, TeamCity, +: refs/heads/* VCS

+3

powershell, , powershell:

$env:BUILD_NUMBER

, .

+1

All Articles