Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity building Git / GitHub pull requests

We have a TeamCity 7.1 installation that builds all branches from a GitHub repository.

GitHub has a notification hook back to TeamCity to trigger a build on check-in. We also have TeamCity polling GitHub every 120 seconds to check for changes (in case the server was offline when a change was checked in).

Our normal development follows a common pattern:

  1. Create a branch from master
  2. Commit to that branch until finished with a feature
  3. When finished, pull from master to merge any changes and push to remote
  4. Submit a GitHub pull request to allow the admins to merge into master

Everything is working swimmingly (after much searching to get the correct configuration settings) however...

The above process triggers several builds on TeamCity and I'd like to know whether they're all necessary. Typically we'll end up with:

  • A build for /refs/heads/branch-name
  • A build for /refs/pull/number/head
  • A build for /refs/pull/number/merge

Naturally the first build is the last check-in on the particular branch, and the second build is the pull request, but what is the third build for?

like image 578
asafb Avatar asked Sep 28 '12 06:09

asafb


3 Answers

Third build is actually the most valuable β€”Β it's the result of pull request auto merge (merge that happens, when you press the button at github).

like image 75
Danila Shtan Avatar answered Sep 29 '22 11:09

Danila Shtan


Your builds seem redundant. The more thrifty way to organize TeamCity builds of feature-branches in git is as follows:

  1. Organize continuous integration of your refs/heads/master branch. 120 seconds poll is quite reasonable here.
  2. Organize nightly-builds for every refs/heads/feature-name branches. As of my experience, only a few of the feature-branches require 120-seconds polling.

TeamCity 7.1 has a very nice feature to autotrigger feature-branches, so step (2) can be setup in a couple of clicks with a branch mask like refs/heads/feature-*.

There is no meaning in building pull requests since they will be covered by master builds.

like image 39
Sergey K. Avatar answered Sep 29 '22 12:09

Sergey K.


Updated answer, in case someone still uses TeamCity πŸ˜‰

Since 2018, there is a native Pull Request Build Feature. This is a better solution compared to using branch triggers & filters, since it creates a two-way link between the build and the corresponding PR and frees you from having to add any refs/pull/... to the VCS Branch Spec.

Still, if you insist on using pull/*/merge: note that this creates superfluous builds in case the "Require linear history" (=only allow Rebase & Squash merges from PRs) feature is enabled on the GH repo, since a PR in such case can only be merged once it is up-to-date with its base branch anyway.

like image 24
conny Avatar answered Sep 29 '22 11:09

conny