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

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


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.