Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 386
Igor Konoplyanko Avatar asked Apr 02 '13 10:04

Igor Konoplyanko


People also ask

How do I find my branch name in terminal?

In order to add branch name to bash prompt we have to edit the PS1 variable(set value of PS1 in ~/. bash_profile). This git_branch function will find the branch name we are on. Once we are done with this changes we can nevigate to the git repo on the terminal and will be able to see the branch name.

How do I find the branch name in Visual Studio?

Visual Studio displays the current branch in the selector at the top of the Git Changes window. The current branch is also available in the status bar on the bottom-right corner of the Visual Studio IDE.


1 Answers

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.

like image 82
DevDave Avatar answered Sep 30 '22 00:09

DevDave