60

I'm wondering how to select the branch to build against using Team City 8.1.

My VCS root (Git) is set to Default: "master" and Branch specifications are

+:refs/heads/develop
+:refs/heads/feature/*
+:refs/heads/hotfix/*
+:refs/heads/master
+:refs/heads/release/*

I have a CI build set up that automatically builds anything that is checked in, which is working exactly how I want.

What I'd like to do is create a scheduled QA build/deployment against the "develop" branch. I see that if I click the ellipsis next to the run button, I can choose the branch on the "Changes" tab, but I'm unable to determine how to make this "stick". Is this possible, or am I going about this wrong?

Thanks,

Joe

Joe
  • 5,389
  • 7
  • 41
  • 63

2 Answers2

114

Based on @biswajit-86 's feedback and some other information I found while googling this, I was able to get this to work. Here's what I did (image-heavy, sorry). It's based on Team City 8.2 which seems to be set up a little differently than the examples I came across.

1) Set up a VCS root. Key here is the %BranchName% parameter.

enter image description here

2) Create a Build template and use the VCS root that was just created. I also added an MSBuild step as all of my builds need to run this.

enter image description here

3) Create a new build, based on the template. As you can see here, the %BrachName% parameter that was created in step 1 is available.

enter image description here

4) If you need to change this later, it's available here

enter image description here

And that's pretty much it. For my CI build, I left the branch name empty so any branch that is checked in triggers the MSBuild step. For my QA build, I pass in "develop" as shown here and I have this set up on a daily schedule. I also have a "release" build set up, but based on our naming conventions it looks like I need to update the build to point to the specific branch per release.

Joe
  • 5,389
  • 7
  • 41
  • 63
  • 3
    Teamcity should have this kind of feature ... It is a pitty its not there ... For subversion we could control this through checkout rules ... but not here ... – Sharique Abdullah Aug 12 '14 at 06:02
  • Why do I have to to dig inside the SO to find it? It should be available on the official TC manual. Thank you very much. – kirill.login Oct 31 '19 at 11:31
  • In version 9.1.5, I had to manually define a %BranchName% parameter in each build configuration. I also had to use that parameter to specify a unique checkout directory for each configuration. (The latter issue may have been due to peculiarities in our setup.) Apart from that, it was all quite simple and works fine. – Otto G Mar 10 '20 at 15:04
8

You can parameterize the "Ref name" of the git VCS setup. What this means is you declare a variable of the form %variable.name% in your build, create a build parameter under the "configuration parameter:" category.

For each build target set this value and you should be able to pick the specific branch that you want to run the target for.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
Biswajit_86
  • 3,661
  • 2
  • 22
  • 36