A node.js daemon that syncs Github pull requests with Jenkins jobs, by jamesob at Percolate. Began as a fork of this.
For each open pull request in Github, a Jenkins job is created and builds whenever the associated branch is pushed to. Upon each build, success or failure is posted back to the PR's status.
- Jenkins job per PR, sync'd on the minute
- Github commit status API integration (thanks @mattheath!)
Configure Github's post-receive hooks to fire to URL
http://some-login:some-password@your-jenkins-url/github-webhook/
.
You haven't done anything with that login combination yet, so don't worry. Ultimately, you will use that information to register a Jenkins user that Github can use.
Create an OAuth authorization with a user who has access to the repo being PR'd to and remember it for later. It will be used in a Jennifer environment variable.
- Enable the
git
andgithub
plugins. - For authentication, use Jenkins' own user database. Create a user with the credentials you used in the Github post-receive hook above.
- Create yet another user to be used by Jennifer with full privileges.
- Create a Job which will serve as a template for each PR-specific job. Name
it anything so long as it doesn't begin with
pr_\d+_
; that will be a naming convention reserved for PR-specific jobs. I called thispull_request_job_template
.
-
Configure it with the right Github project, etc.
-
For Source Code Management, select Git and specify the repo URL, etc., but for Branch specifier, put
${pr_branch}
. This is a sort-of-horrible hack wherein that special identifier is substituted out for the actual branch associated with a given PR. -
Under Build Triggers, select Trigger builds remotely.... Pick an authentication token and remember it for later.
-
Again under
Build Triggers
, select Build when a change is pushed to GitHub. -
Under Build, run your tests, etc., but within the same script as running your tests, establish an environment variable (maybe called
SUCCESS
?) that is set tosuccess
if your build succeeded and something else otherwise. Have this run after the build is complete:curl "http://your-jennifer-url:3000/jenkins/post_build?\ user=gh_user_who_owns_the_repo\ &repo=gh_repo\ &sha=$GIT_COMMIT\ &status=$SUCCESS\ &job=$JOB_NAME\ &build=$BUILD_NUMBER"
There might be some spacing issues there, but you get the picture.
-
Optionally, add a similar curl call to the beginning of the build script to signal to Github that the build is in progress.
curl "http://your-jennifer-url:3000/jenkins/pre_build \ user=gh_user_who_owns_the_repo\ &repo=gh_repo\ &sha=$GIT_COMMIT\ &status=pending\ &job=$JOB_NAME\ &build=$BUILD_NUMBER"
- Clone this and install dependencies with
npm install
. - Establish all environment variables as dictated by
env.coffee
. These should be similar to the some of the values used above; hopefully after faring the above instructions, you will have an intuition for the naming. - Run it with
node server.js
. It will log out tojennifer.log
.
After that, you should have a few new jobs in Jenkins. They should (not by coincidence) match the pull requests you currently have open. Status will be updated as pushes happen. Commit statuses will be updated in GH according to the result of the Jenkins build. Hooray.