Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git short branch name in teamcity

I'm using teamcity 8.x.x version.I configured my Teamcity for continuous deployment. I'm need a feature branching deployment. I see this document "http://confluence.jetbrains.com/display/TCD8/Working+with+Feature+Branches".

I'm trying this document implementing on my Teamcity. I have a problem.

My deployment config use "OctoPack" (nuget). My nuget package needs build count and branch name. example: 1.0.0.356-feature-1.

I'm try this versioning,

%build.number%-%teamcity.build.vcs.branch.VCS_ROOT_ID% ----> 1.0.0.356-refs/head/feature-1

this version not support nuget versioning. nuget not comparative "/".

I need this,

%build.number%-%teamcity.build.vcs.SHORT_BRANCH_NAME.VCS_ROOT_ID% ---> 1.0.0.356-feature-1

how can I ?

Thanks

like image 303
Ömer Faruk Aplak Avatar asked Dec 11 '13 08:12

Ömer Faruk Aplak


People also ask

What is default branch in teamcity?

The default branch allows using different branches in different VCS roots (for example, if one of the roots is Git and another is Mercurial) and in different builds when they are linked by a snapshot dependency.


2 Answers

I believe what you need is another variable. Try using %vcsroot.branch%. There is also %teamcity.build.branch%, but that one will contain "<default>" on the default branch. If you want more flexibility to choose exactly which part of the branch name gets selected, you can follow the instructions on this page:

http://confluence.jetbrains.com/display/TCD7/Working+with+Feature+Branches#WorkingwithFeatureBranches-branchSpec.

like image 119
Pedro Pombeiro Avatar answered Oct 22 '22 18:10

Pedro Pombeiro


I found that if you have one branch set up in the VCS, then %teamcity.build.branch% is not defined. And if you have multiple branches defined, then %vcsroot.branch% only reports on the the name of the default branch.

I ended up using a git command to give the current branch name.

Powershell:

$branch = (git symbolic-ref --short HEAD) | Out-String

Command Line:

FOR /F "tokens=* USEBACKQ" %%%%F IN (`git symbolic-ref --short HEAD`) DO ( SET branchName=%%%%F ) ECHO %%branchName%% 

TeamCity converts all %% -> % so that's why there are so many %

Set as environment variable

If you would like to use the branch name as an environment variable to be used in other steps of your project you can set the branch name by using Powershell as an example. First define env.currentBranch in your build configuration and then set it with the following powershell as your first build step.

$branch = (git symbolic-ref --short HEAD) | Out-String Write-Host "##teamcity[setParameter name='env.currentBranch' value='$branch']" 
like image 34
soniiic Avatar answered Oct 22 '22 18:10

soniiic