Triggering builds by pushing tags on Git. What is best practice? Follow
We are in the process of migrating our main repository from Mercurial to Git. Our build process involves tagging builds with different tags and the build process is different depending on the tag (or if there is no tag). So we need adding a tag to kick off a build.
In Mercurial, tagging is done by making a commit so adding a tag naturally causes a new build. On git, a tag is not a commit and by default, Team City does not start a new build just because a tag has been added to the repo. I am aware of how to make Team City trigger a build when I make a new tag (in git):
- Enable "use Tags as Branches" in the VCS root
- Add refs/tags/* to the branch filter.
- set parameter teamcity.vcsTrigger.runBuildInNewEmptyBranch to true
(not sure if all of the above are needed, please advise if some are not)
This works: adding a tag causes a new build. However there are some problems. During the build the "branch" of the build (which is shown prominently in a blue lozenge) is shown as the tag name preceded with "refs/heads". It's not possible to see the branch name for the build. Is it possible to show the branch name in the blue lozenge despite the above settings? It seems TC is regarding branches and tags as identical which is not really ideal.
In general are the above settings best practice for my use case? Is there a more straightforward way to get Team City to work with Git when triggering builds with tags or is there a better way? It is strange Team City seems to work better with hg than git (at least with default settings) which is surprising!
Please sign in to leave a comment.
The branch name you see in the UI is the logical branch name. You can get rid of the
refs/headspart, but you can't change the name of the branch itself. TC treats tags as branches because of the corresponding setting in the VCS Root. Otherwise, it'd completely ignore them.
In Git, tags are just names assigned to specific revisions. They do not belong to any branch but exist independently. And the particular tag can be present in different branches. E.g., when you execute something like this:
git branch --contains tags/<tag>, the output can contain several branches with the same tag. In that case, which branch would you expect to see in the branch selector in the TC UI?
I'm not a Mercurial expert, but by the sound of it, Mercurial treats tags differently.
Maybe you should consider rethinking how you trigger builds in TC with Git? You mentioned that initially, you used tags to trigger different builds because the build process should be different for different tags. Maybe you can utilize the VCS Trigger Rules instead. Using these rules, you can configure a VCS Trigger to only fire builds in a specific build configuration when, say, a particular pattern is present in the commit message. This way, you can have, e.g., a couple of build configurations where one would only trigger commits without this pattern, and the other would only trigger builds when the pattern is present in the commit message.
And if you need tags to be present in the VCS itself, the second build can utilize VCS labeling.
The way you do it is correct. It's not like TC works better with HG than with Git when it comes to tags. It just looks like in these systems, tags are not entirely the same things.
If the proposed solution doesn't suit you, please elaborate on why you want to trigger builds with tags in Git but do not want to see the tag name as the branch name in the TC UI. The more we understand the situation, the better solution we may be able to provide.
Here's a link to our documentation that covers the VCS Trigger Rules. I forgot to provide it in the above comment.