I want to provide a git tag to the TeamCity server to build it.
I pass the tag (i.e. release_1.1
) as a parameter to the job. So inside the job the tag is available as %tag%
, but under the Version Control Settings
I don't see any way to use this parameter so the server can checkout this tag.
Is there any way this parameter can be used in the settings to checkout the tag?
-
I'm getting a similar issue - setting the "Branch Name" to "refs/tags/%TagToBuild%" I get: `Failed to collect changes, error: Argument 2 for @NotNull parameter of jetbrains/buildServer/buildTriggers/vcs/VcsRootChangesLoader.loadChanges must not be null` – Zhaph - Ben Duguid Feb 19 '14 at 14:10
4 Answers
- Go to Edit Configuration Settings -> Version Control Settings
For all your VCS roots for this build configuration click Edit and then:
- put '+:refs/tags/*' into Branch specification textbox
- check Use tags as branches
Then you'll be able to choose a tag when you press the '...' button beside run.

- 91
- 1
- 9

- 4,273
- 2
- 24
- 24
-
IMHO, this is by far the cleanest most native way to go. Tags are available as are branches via custom Run dialog. no need for anything custom with variables. you can then use the branch specification for all other aspects of the build configuration like normal. – Mar 06 '15 at 02:58
-
1I agree that this seems to be the cleanest way to build a tag. It should be mentioned, that a custom build is necessary, to choose a tag. – Rias May 05 '15 at 18:41
-
1And also wait for 30 seconds and refresh your TeamCity page before pressing Run – Maxim Eliseev Mar 01 '16 at 11:55
-
4Not sure if I understand this step, teamcity builds master by default I don't get any prompt to select a tag: http://i.imgur.com/CnT8XBN.png I am on TeamCity Enterprise 9.1.3 – zengr May 19 '16 at 22:00
-
-
1ok so I had to go to the projects page in teamcity, then click on the small menu "..." icon right of the "Run" button. This gives you a dialogue with the 4 tabs. The second says "Changes", in there you can specify the tag you want to build from in the "Build branch" drop down. I'm using TeamCity version Enterprise 9.1.5 (build 37377) – Jeremy Sep 23 '16 at 11:11
-
You can also use configuration parameter `teamcity.vcsTrigger.runBuildInNewEmptyBranch=true` to tell TeamCity to build on all commits -- https://youtrack.jetbrains.com/issue/TW-43606 – Marc Durdin Jul 03 '17 at 08:43
I've managed to get the following working:
In the Build Configuration, under "Build Parameters":
Define a Configuration Parameter:
- Name:
TagToBuild
- Kind:
Configuration parameter
- Value:
- Spec:
- Label:
Tag to build
- Description:
This should be the full path to the tag, i.e. refs/tags/0.5.5
- Display:
Prompt
- Type:
Text
- Label:
Note that the "value" field was intentionally left blank.
Then, in the VCS Root:
- Branch Name:
%TagToBuild%
When I run the build, I'm then prompted to supply a branch/tag name:
Entering a value such as refs/tags/0.5.0
results in a nice build, with the branch name listed in the results:
If you try to help the user in any way beyond the description, this seems to fail. So you can't do any of the following:
- In the Configuration Parameter set the "Value" to
refs/tags/
and have the user add the tag name. - In the VCS Root set the "Branch Name" to
refs/tags/%TagToBuild%
.
In both cases on our slightly old (7.1) instance of Team City I got the error:
Failed to collect changes, error: Argument 2 for @NotNull parameter of jetbrains/buildServer/buildTriggers/vcs/VcsRootChangesLoader.loadChanges must not be null

- 26,785
- 5
- 80
- 117
-
4You can override the branch name by creating a parameter with name `teamcity.build.branch`, this way you can override the branch and set it to whatever you want, i.e. `release` – js3dev Feb 28 '14 at 16:15
-
1Although it's not strictly my case, your answer gave me a hint which helped me solving an issue I've been struggling for days! I wish I could upvote it twice. Thanks a lot! – Yan Sklyarenko Feb 29 '16 at 19:54
-
2With a later version of TeamCity (eg. we are using 9.1.5), it now _does_ work to set the "Default branch" of the VCS root to something like `refs/tags/%versionRoot%`, which is a bit cleaner than having to type the full path each time – gezzahead Jun 28 '16 at 15:03
I've not done this with tags, but I've done this with branches. I tell TeamCity to build all branches by specifying it should build +:refs/heads/*
. Now whenever I push any branch, TeamCity builds it. Then within the build I then use git branch
and look for the line that starts with a *
. I embed that branch name in a convenient spot (AssemblyInfo.cs for .NET, package.json for node.) see http://confluence.jetbrains.com/display/TCD8/Working+with+Feature+Branches

- 13,017
- 7
- 36
- 63
-
1But that's still building everything. What I think js3dev is looking for (and I know I am) is a way to mark a point in the repo with an easily identifiable tag and build that - some of my tooling will create different versions of .config files for different environments, but I only want to build for "release" when I've passed QA, but the head may have moved on for some reason. – Zhaph - Ben Duguid Feb 26 '14 at 10:19
-
Typically when I have this need, I create a new branch -- `Releasev2.7` for example -- and push the branch. TeamCity's "build all branches" picks it up and runs with it. – robrich Feb 28 '14 at 20:46
You need to specify the tag format in refs/tags/${tagName}
.
So yours would be refs/tags/release_1.1
.

- 5,138
- 3
- 29
- 43
-
2If I specify `refs/tags/${tagName}` as the Default branch, TeamCity starts complaining that it can't connect to the git repo, isn't there a cleaner solution? this should be a very common use case. – js3dev Dec 12 '13 at 14:13
-
Setting my branch name to `refs/tags/${%tag%}` results in the error: "Cannot find revision of the default branch 'refs/tags/${0.5.0}'", but setting it to `refs/tags/%tag%` results in "Failed to collect changes, error: Argument 2 for @NotNull parameter" – Zhaph - Ben Duguid Feb 19 '14 at 15:25
-
1Looks like if you set the Default branch to `%full_tag%` instead of `refs/tags/%tag%` and default full_tag to be empty, TeamCity won't complain. But you would need to pass the full reference as the parameter though (i.e. full_tag=`refs/tags/development-12`). – js3dev Feb 28 '14 at 16:11