Recipe 1.12 Integrate Jenkins CI with GitHub
Problem
You wish to integrate a GitHub repository with Jenkins CI.
Solution
The Jenkins GitHub plugin provides support for receiving push notifications from Github post-commit hooks and using those notifications to trigger jobs within Jenkins. It can set-up the post-commit hooks in GitHub for you.
In addition, GitHub decorates the Jenkins “Changes” pages with links to the pretty GitHub commit, issues pages and adds a sidebar link to the corresponding GitHub project page.
We will need to install the plugin:
Go to your Jenkins instances root page.
If your Jenkins instance has security enabled, login as a user who has the Overall | Administer permission.
Select the Manage Jenkins link on the left-hand side of the screen.
Select the Manage Plugins link.
On the Available tab, select the Github Plugin and click the Download and Install button at the bottom of the page (if you do not got the Git Plugin installed, do not worry, Jenkins is smart enough to install/upgrade the Git plugin, where required).
Restart Jenkins once the plugins are downloaded (Note: users of Jenkins 1.442 or newer should be aware that the plugin currently requires a restart to function correctly).
To enable build triggering, you need to configure your Jenkins instance for receiving the push notifications from GitHub:
Go to your Jenkins instances root page.
If your Jenkins instance has security enabled, login as a user who has the Overall | Administer permission.
Select the Manage Jenkins link on the left hand side of the screen.
Select the Configure System link.
In the GitHub Web Hook section select the Let Jenkins auto-manage hook URLs option.
Ensure you have provided at least one username and password for connecting to GitHub (the password is required as GitHub does not expose an API for managing the Post-Receive URLs).
Once you have configured your Jenkins instance for receiving the push notifications, you can enable jobs being triggered via the push notifications:
Goto your Jenkins instance job.
Select the Configure link on the left hand side of the screen.
Select the Build when a change is pushed to GitHub checkbox and save the configuration.
Discussion