Jenkins and Github Pull Requests

by Buddy Lindsey on April 16, 2013

Jenkins Logo

One of the things people love about travis-ci is it will build pull requests, but most people don’t realize Jenkins can do pull requests as well. It is also very simple to configure Jenkins to do pull requests using the correct plugin.

Install the Plugin

Install this plugin through the manage Jenkins admin section.

Configure Github User

This is fairly simple. Follow the trail of links then add the relevant information. Make sure you have a user you want to access github with, and they have the appropriate permissions for the repos.

  1. Manage Jenkins
  2. Configure System
  3. Find Github pull requests builder Configuration Section
  4. Fill in the relevant information similar to the image below

System Configuration

Configure Your Git Pull

You need to configure where Jenkins pulls from Github to build pull requests. Specifically Github stores all the pull requests in a “secret” location. It isn’t really secret, but most people don’t explore where refs are stored. So adding the following to the correct refspec is a must. In the advanced tab of the your git configuration add the following:

+refs/pull/*:refs/remotes/origin/pr/*

In the branch specifier section add:

${sha1} 

Here is what that section should look like:

Git Configuration

You also need to set Build triggers and add users to the whitelist so people whom submit pull requests can have their pull requests automatically build. If you don’t add people to the white list you will need to tell Jenkins to build the PR.

Build Triggers

Your Done

If everything was configured correctly. Your pull requests will look like this at the bottom of the PR:

Successful Build

Conclusion

Pull requests create an awesome workflow, and really help teams collaborate on a lot of different parts of code. The real problem has been, for a while, that the Pull Requests are outside the main refspec and will not build on a push. So with the pull request builder plugin it targets the location the PRs are at. The best part is it tells you the build status of the build inside the PR, similar to Travis-ci. If you aren’t using Jenkins or Github PR’s I recommend starting.

Related Posts:

Was this Helpful?

If you found this article useful you might find others useful as well. Please browse the archives and subscribe to the RSS Feed to stay up-to-date.

Spencer August 20, 2013 at 6:27 am

Hey Buddy,

Great article, I am trying to use your tutorial to get Jenkins to build my pull requests. My only problem is I am not getting any notification on GitHub saying that the builds are successful or failing. Did you have to install another plugin to get the message you show above on GitHub?

Reply

shir avr September 11, 2013 at 1:49 am

Hey Spencer,

well No, make sure that the github’s user you connect to jenkins has a administrator permission on the repository.

Reply

Leave a Comment

Previous post:

Next post: