Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic merge of feature branches in TeamCity not working

Tags:

git

teamcity

We're using TeamCity Professional 9.1.1 with Git/Stash for version control and I'm trying to get automatic branch merging working.

Our scenario is that the devs create feature branches from master named feature/name-of-feature. Once the feature is ready for testing they merge the branch into an integration branch. We'd like to automate this in teamcity.

I've managed to get feature and bugfix branches building automatically by adding this to our Branch specification: in the VCS root for the master branch

+:refs/heads/feature/*
+:refs/heads/bugfix/*

But I'm struggling to get the feature branches to merge automatically into the integration branch. I've added an automatic merge build feature and I've tried various combinations of 'Watch builds in branches' and 'Merge into branch:' For 'Watch builds in branches' I currently have

+:feature*
+:bugfix*

and for 'Merge into branch:'

integration

and I've also tried

+:feature/*
+:bugfix/*

and

+:refs/heads/feature/*
+:refs/heads/bugfix/*

The builds are successful but the branch doesn't get merged into integration and there are no messages in the log.

Any ideas what I'm doing wrong?

like image 337
Ian Oakes Avatar asked Nov 09 '22 20:11

Ian Oakes


1 Answers

I know this is an old post but I just ran into the same scenario where the automatic merge was not being triggered (I'm using TC 2017). Note that because I don't know much about the OP repo I might be a bit off to solve this particular question, but perhaps I could help future visitors. In general, there are three things to be configured, the VCS, the automatic merge itself and the build triggers.

  1. In the VCS settings you must include the branches that you want to monitor for merges. These would be in addition to the default branch.
  2. In the Automatic Merge build feature you specify the source branch(es) that you wish to merge and a single branch to merge to.
  3. The trigger is where I was failing. In my configuration I was monitoring changes in the default branch in the VCS, meaning that in this particular build configuration the branches to merge from were never built (on purpose). But according to the Team City documentation (I added the bold section):

The Automatic Merge build feature tracks builds in branches matched by the configured filter and merges them into a specified destination branch if the build satisfies the condition configured (e.g. the build is successful). The merge occurs after the build finishes.

What's not immediately clear is that The merge occurs after the build on the source branch finishes. So, in short my issue was that my triggers were configured to only build the default branch, so the feature branches never build and thus never merged.

P.S. If you asked me I'd change the behavior so that merges happen regardless of the branch that triggered it, but I understand it would be hard to control scenarios where the feature branches have bugs and don't compile, TC could maybe run a build before the merge and another after, but this could have a big performance impact on the runners.

P.S.S. Another option is to configure it the way around (which is what I intend to do further down the line). Because I have separate builds for the feature branches, I will configure the automatic merge there, to push the changes that just built into the main branch. This should automatically also trigger a build on the main branch, completing the cycle.

like image 136
PedroC88 Avatar answered Nov 15 '22 06:11

PedroC88