Trigger a build on applying a tag
Asked Answered
R

4

16

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.

Ropeway answered 18/5, 2017 at 11:32 Comment(1)
Tried replacing +:Demo* with +:refs/tags/Demo*?Selftaught
F
12

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.

Family answered 3/7, 2017 at 8:45 Comment(4)
Doesn't that cause a new build to run for every new branch pushed?Offence
@BigMoney, yes, it can, but then you can use branch filters in your triggers to restrict the branches you wish to run against.Family
This doesn't seem right? Does runBuildInNewEmptyBranch mean new branches and new tags?Antennule
@StormMuller, yes, AFAICTFamily
D
5

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

Dormeuse answered 24/4, 2018 at 8:14 Comment(3)
This is not particularly useful with all the image links broken.Pontone
I see the images just fineDormeuse
Probably blocked by filtering software. My apologies.Pontone
C
1

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.

Cop answered 15/11, 2019 at 8:58 Comment(1)
How can I prevent trigger to run on any new change to branch and only run build on new tag creation only?Sudduth
R
1

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

Rondon answered 7/8 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.