Trigger build on specific branch merges to master
I am trying to find a way to trigger a build on the master branch when a specific branch is merged into it. I am adopting a git-flow approach, so in this case, one of the requirements is to trigger a release build job when a hotfix branch is merged to the masterbranch.
I tried the following settings on Teamcity:
VCS Settings:
-
Default branch:
refs/heads/master -
Branch Specification:
+:refs/heads/hotfix*
Trigger Settings:
-
Trigger: VCS Trigger
-
Parameter, VCS trigger rules: +:hotfix*
The problem is that any branch which is merged to master is triggering the build, but I only want to restrict the build to be only triggered on hotfix merges only.
Is this even possible on Teamcity? The documentation gives a vague overview with regards to this topic
Triggering a Build on Branch Merge
The VCS trigger is fully aware of branches and will trigger a build once a check-in is detected in a branch.
When changes are merged / fast-forwarded from one branch to another, strictly speaking there are no actual changes in the code. By default, the VCS trigger behaves in the following way:
-
When merging/fast forwarding of two non-default branches: the changes in a build are calculated with regard to previous builds in the same branch, so if there is a build on same commit in a different branch, the trigger will start a build in another branch pointing to the same commit.
-
If the default branch is one of the branches in the merging/fast-forwarding, the changes are always calculated against the default branch, if there is a build on same revision in the default branch, TeamCity will not run a new build on the same revision.
Please sign in to leave a comment.
Hi James,
Thanks for your request. There's a couple things to take into account here. First, you only mention wanting to trigger on merges onto master from hotfix branches. If you aren't interested in hotfix builds by themselves (or at least on this configuration), then you could remove the hotfix branches from the specification.
The usual scenario here would be to make sure that the merges are identifiable by something, such as a specific string on the commit message (for example "merge branch hotfix/* into master"), which would make filtering out other merges much easier. The issue here is that you aren't actually looking into including merges in the trigger, but excluding what isn't a merge from hotfix.
If you also want to build on hotfix (which I guess is the case), that would make the single VCS Trigger much more complex, so the best option would likely be to extract a template, spilt the build configuration in two, one for hotfixes, and the second one for merging the hotfixes into master, coming back to the previous point about making the merges build.
Second, the documentation doesn't really cover your use case, those points are mentioned because it's a common scenario where some builds aren't being triggered because they've been already built on the default branch and it's a behavior that needed explanation, judging by the amount of requests we received about it.
Hope this makes sense.