Github Hooks for Jenkins Continuous Integration

Over the last iteration we spent some time perfecting our continuous integration environment. We’ve started using Jenkins (the CI environment previously known as Hudson), and so far we’re pretty happy. One thing that vexed us for a while was getting a GitHub service hook to trigger our builds.

Here’s what we had to do:

1. Create a “GitHub” account with Jenkins.

The credentials from this “github” user account are required for GitHub to gain access to the build URL. We’re using the built-in Jenkins user database with matrix-based authorization. So we added a “github” account using the “sign up” functionality, and then gave that user “Overall: Read” and “Job: Read” permissions. We’re not totally sure why these particular permissions are required, but we are sure that the URL-based build trigger doesn’t work without them!

Creating a “github” account in Jenkins

Creating a “github” account in Jenkins

2. Configure Remote Build Trigger

On the “Configure” section of the Jenkins job you’re setting up, check the “Trigger builds remotely” box (under the “Build Triggers” section), and set some long random authentication token:

Configuring Remote Build Trigger

Configuring Remote Build Trigger

3. Configure a Post-Receive URL at GitHub

Here’s what the URL for GitHub should look like:

http://GITUSER:GITPASSWORD@pathtojenkins.com/job/YourProjectName/build?token=LONG_RANDOM_TOKEN

GITUSER and GITPASSWORD pertain to the “github” user you created with Jenkins. Also, don’t forget to include the port Jenkins is running on if it’s not port 80. Add this to your GitHub repository by visiting the “Service Hooks” Admin section of the project you’re setting up. Here’s about what it should look like:

Configuring a Post-Receive URL at GitHub

Configuring a Post-Receive URL at GitHub

Hopefully this saves you some time if you are looking to use Jenkins and want to use a GitHub service hook to trigger your builds.

And let us know if you have any questions, comments, or suggestions! Thanks.


Interested in working with experts like this at Foraker Labs? We'd love to talk about what you have in mind. Contact us today for more information.