43

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

Ömer Faruk Aplak
  • 889
  • 2
  • 9
  • 21
  • Can you share how you solved this? – Lars Stenberg Feb 12 '14 at 10:59
  • 1
    Hello, try this, %build.number%-%teamcity.build.branch% – Ömer Faruk Aplak Feb 12 '14 at 14:04
  • 5
    @LarsStenberg, I know this maybe too late, but I was thinking the same question when I saw the accepted answer. So I add this comment if anyone else need help in the future. Actually what you need is the branch specification to give you the correct logical branch name. This is the clearly mentioned here: https://confluence.jetbrains.com/display/TCD10/Working+with+Feature+Branches#WorkingwithFeatureBranches-Logicalbranchname. Then you can use %teamcity.build.branch% as it is basically the logical branch name. – bigbearzhu Oct 14 '16 at 00:17
  • @bigbearzhu Can you please add that as an answer? I'd do it myself but you should get the credit for it. – JamesQMurphy Dec 31 '18 at 16:55

2 Answers2

34

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.

Pedro Pombeiro
  • 1,654
  • 13
  • 14
  • thank you very much, been looking everywhere for this – chester89 Feb 21 '14 at 11:24
  • 17
    Actually it's %teamcity.build.branch%. %vcsroot.branch% just gives you whatever the default is set to, which is usually much less useful than what most people are looking for. – starmandeluxe Aug 21 '17 at 08:03
  • to deal with the branch name - if one wants to use branch name e.g. as a part of the zip file artifacts would go to - there is a useful post here: https://stackoverflow.com/questions/42922880/teamcity-show-branch-in-artifact-zip-name – Mr. Girgitt May 21 '19 at 09:49
2

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']"
soniiic
  • 2,664
  • 2
  • 26
  • 40