How do I get TeamCity to automatically merge a Git feature branch with master and fail the build in case of merge conflicts?
Asked Answered
S

1

9

Our development/release cycle works like this:

  1. Developer creates a feature branch, implements a feature
  2. Developer indicates feature is ready for acceptance testing (UAT)
  3. Tester deploys feature branch and accepts (or rejects) feature

Accepted features are then merged into the master branch by the tester, and will therefore be released during the next release cycle (we deploy the trunk/master code weekly).

We're having frustrations with merge conflicts, because by the time the tester has UAT'ed the feature and discovered that it won't merge cleanly, the developer who worked in it has normally moved on to something else.

We're considering a solution whereby every feature branch is automatically merged, by TeamCity, against the current master branch, and any build resulting in a merge conflict is considered a failed build - this will give us early visibility on problematic merges so we can fix them sooner.

TeamCity doesn't appear to have built-in support for this workflow (i.e. when a push happens to branch X, checkout master, merge branch X onto it, build, unit-test, create package). Has anyone created a similar workflow using TeamCity and Github - using custom msbuild targets, perhaps?

EDIT: I should clarify that we're using Github but we're not currently using pull requests - sounds like this is something I should investigate. :)

Scrouge answered 16/6, 2013 at 12:33 Comment(1)
Great question Dylan, I'm looking to solve the same issue myself. When you mention GitHub in the last sentence, do you mean Git instead? Because GitHub already implements this feature. I already take advantage of it in open source projects.Guajardo
E
2

If you're using Github and Pull Requests then check out Hadi Hariri's blog post about how to get the pull request after it has been merged with master:

http://hadihariri.com/2013/02/06/automatically-building-pull-requests-from-github-with-teamcity/

Github does an automatic merge for every pull request and the resulting merge is available (though pretty much undocumented) as

git fetch origin +refs/pull/298/merge

where pull request id is 298. And so all merged pull requests can be fetched with a wildcard in place of the id in Teamcity and be built automatically. The branch specification would look like this:

+refs/pull/*/merge

EDIT: You say you're not using pull requests so I guess you could do this with some git commands. I haven't tried this out myself so these are only a few tips to get you started.

  1. Use the branch specification feature in Teamcity to get the branch. Set the checkout mode to check out the code on the agent
  2. In a build step merge the master branch into the target branch. If master is not available on the agent you might have to fetch it first. If you get any errors, then the build fails.

To check for merge conflicts, one of these strategies should work.

Elenoraelenore answered 16/6, 2013 at 21:38 Comment(3)
@Dylan-Beattie Are you going to use Pull Requests in Github or are you thinking about implementing your own flow in Teamcity?Elenoraelenore
The Github pull request feature is almost exactly what we were looking for - we're in the process of migrating from Subversion and not completely up to speed with all the Github bells & whistles yet :)Scrouge
@DanielLee I don't see a build step option that lets you merge master into a given branch. How do you do this?Krenek

© 2022 - 2024 — McMap. All rights reserved.