How to set buildNumberPattern with short vcs number?

I'm trying to set a custom buildNumberPattern  like this

buildNumberPattern  = "1.0.%build.counter%.${"%build.vcs.number%".take(7)}"

I've tried it in mutliple ways but I always get 1.0.###.%build.

Is there a correct way to set this? Or isn't it possible?

0
1 comment

Hi Shauli,

In TeamCity, the buildNumberPattern does not support direct string manipulation functions like .take(7).

However, you can achieve the desired result by using  ##teamcity[buildNumber '<new build number>'] service message way to override the build number dynamically during the build. Use a Command Line or PowerShell step:

Linux/macOS (Bash)

SHORT_HASH=$(echo %build.vcs.number% | cut -c1-7)
echo "##teamcity[buildNumber '1.0.%build.counter%.$SHORT_HASH']"

Windows (PowerShell)

$shortHash = $env:BUILD_VCS_NUMBER.Substring(0,7)
Write-Output “##teamcity[buildNumber '1.0.%build.counter%.$shortHash']”

Best Regards,

Tom

0

Please sign in to leave a comment.