Pradeep
Pradeep

Reputation: 3276

Trigger a build on applying a tag

I want to achieve the following:

  1. Anyone in the dev team creates a tag i.e. Demo_Build_1 to dev branch.
  2. TeamCity should be able to detect this new tag and build only this tag.

I have enabled "treat tag as a branch" checkbox in VCS configuration.

I have tried configuring it but I am not able to get it working. Following is my VCS setting: enter image description here
and following is how I have configured my build trigger: enter image description here

I don't want to trigger a build manually. My idea is that TeamCity should be able to pick up this new tag and run the build. Any pointers to achieve this objective would be helpful.

Upvotes: 16

Views: 9458

Answers (4)

Dimitris Magdalinos
Dimitris Magdalinos

Reputation: 21

I recently had the same question and this thread helped to find the solution with one alteration to @jsaddwater answer:

Instead of creating two VCS Roots in the Version Control Settings just under the VCS Roots list click on -> Show advanced options and add in the Branch Filter:

+:*
-:<default> 

Version Control Settings -> Advanced Options

Upvotes: 1

Dariusz Woźniak
Dariusz Woźniak

Reputation: 10350

My configuration is very similar, but yet slightly different, to the @jsaddwater's one:

Version Control Settings > Branch Filter:

+:*
-:<default>

Version Control Settings > VCS Root:

  • Default branch: master

  • Branch specification:

+:refs/tags/*
-:<default>
  • ☑ Enable to use tags in the branch specification

Triggers > VCS Trigger:

  • Branch filter: (leave empty)

Parameters:

Add or set Configuration Parameter: teamcity.vcsTrigger.runBuildInNewEmptyBranch with the value = true.


Tested and working on TeamCity 2019.1.5.

Upvotes: 1

jsaddwater
jsaddwater

Reputation: 1829

Since I haven't found any complete answer I thought I'd spare someone a couple of hours of hit-and-miss work. I didn't manage to ONLY build tags by editing branch specifications. Using a branch specification in the VCS trigger as well as in the VCS root leads to no builds. Adding a -:refs/heads/dev branch specification will still build commits in the branch. As a workaround one could create an unused branch, and specify that as the default branch. That way, since noone commits to that branch, no regular commits will be build, and tags will always be built.

  1. Create a second VCS root that only monitors tags
  2. In the branch specification of the second VCS root remove the default branch you don't want to build on regular commits and add refs/tags/*
  3. Add a VCS trigger without a branch filter
  4. This is what the trigger settings should look like
  5. Add the magic configuration parameter

This is how my setup looks like: enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Upvotes: 5

Marc Durdin
Marc Durdin

Reputation: 1803

You've got it nearly right. You can use configuration parameter teamcity.vcsTrigger.runBuildInNewEmptyBranch=true to tell TeamCity to build on tag creation -- https://youtrack.jetbrains.com/issue/TW-43606. Otherwise TeamCity won't trigger a build when you see a new tag.

Upvotes: 12

Related Questions