Michael Sync

Michael Sync

Crisp, minimal personal blog

05 Apr 2014

TeamCity Tip: Building all pull requests and updating the status to Github


Merging all pull requests and build all branches

Let’s talk about how we work with github. We keep the master as a stable branch and if we need to work on new feature or bug fixes, we create another branch and push it as a pull request once we’ve done the job. So, another guy can review the code and merge it to the stable branch. The challenge here is that we like to know whether there is any conflict or test failures before we merge the code or not. Do we have to pull the latest, merge the code manually and run the tests to see the result? Would it be nice if your CI can tell you automatically after you’ve done your pull request?

if the answer is yes, here  is the solution for you. In the version control setting of your TeamCity project configuration, you can specify the branch specification. All you need to do  is adding two lines as below in “Branch specification” textbox and trigger the “run” button again.

Github - Merge all pull request and build them all

You will see the statuses of all branches (including merges) in your TeamCity dashboard. pretty cool, huh? But of course, you will have to open your TeamCity home page to see the results. Would it be even nicer if you can see it on github itself?

Github - Merge all pull request and build them all on TeamCity

Updating the commit status to Github

Github provides us the API for updating the commit status. Please refer to this official post “Commit Status API” for details.

Github - Merge all pull request and build them all on TeamCity

Don’t worry! You don’t have to worry about reading the spec or writing any code for it.  There is an awesome TeamCity plugin “TeamCity.GitHub” written Eugene Petrenko. You can download this plugin from his github repository and build it by yourself or you can just download it as zip file from TeamCity’s build artifact.

Steps:

  1. And then put that zip file (No! don’t need to extract it) to <TeamCity Data Directory>/plugins. If you are not sure whether that folder is then you can check about it in your TeamCity Global setting page.

TeamCity - Global Setting

  1. Please restart the TeamCity service

  2. Go to your team city project configuration => Build Steps. And click on “Add build feature” button. You will see the dialog below and select “Report change status to GitHub”.

TeamCity - Add Build Feature

  1. Fill up the required information such as user name, password, repository and etc. You can use the same URL that I mentioned in my screenshot unless you are using GitHub Enterprise.

Report change status to Github

Then, Good to go!

If your pull request is in good shape, you will see something like that at the bottom of your pull request in github.

your pull request is cool

Otherwise, you will get this. meaning you will have to do some manual works.

your pull request is bad for now

Ok. That’s all I know.. and that’s how we are using it.. If any feedback or comment, please shot.. Thanks!