Igor Konoplyanko
Igor Konoplyanko

Reputation: 9374

Branch name in build number

I'm trying to put branch name into build number, but I can't find the right parameter. I'm using build number format : %teamcity.build.branch%.{0}

It works, but when it trying to build default branch 'dev', teamcity names it as <default>.

enter image description here

How to fix it ?

Upvotes: 7

Views: 5014

Answers (2)

DevDave
DevDave

Reputation: 1049

I was able to solve this problem by:

  • In my VCS Root - using git - set my Default Branch to: master
  • In my VCS Root - using git - set my Branch Specification to:

    +:refs/heads/(master)

    +:refs/heads/(release-*)

    +:refs/heads/(hotfix-*)

  • Create a Configuration Paramater: BuildNumberPrefix = SomeService.%teamcity.build.branch%.release_

  • Set my Build number format to: %BuildNumberPrefix%%build.counter%

  • Then in my build steps add a command line step as the first step with the following script:

    set t=%BuildNumberPrefix%%build.counter%

    echo ##teamcity[buildNumber '%%t%%']

In the Team City projects listing when building the project you should see the part of the build number get removed after the command line step is executed. For some reason re-evaluating the BuildNumberPrefix that uses the teamcity.build.branch variable causes the default to go away and be replaced by the branch name.

Hope this helps someone.

Upvotes: 12

max
max

Reputation: 496

See if it helps you solve the problem. Quoting the first comment from http://youtrack.jetbrains.com/issue/TW-24147:

We use a special branch name (<default>) for a reason: when there are several VCS roots with different default branches, we need a single branch name for the build. You can get a real branch name used in VCS root from build parameter teamcity.build.vcs.branch.<canonical VCS root name>. Search for teamcity.build.vcs.branch. on "Build Parameters" tab of the build in UI.

Upvotes: 0

Related Questions