This page explains how to integrate Jenkins builds into a GitHub workflow. In particular:
a Jenkins build gets triggered by any PR or any update to any PR
the outcome of the Jenkins build outcome is displayed on GitHub
a Jenkins build failure disables the GitHub merge button
Instructions
start:
an existing repo
a Jenkins machine
end:
one more job on Jenkins
GitHub repo linked
Create Job on Jenkins
install plugin
Log into builder.openwsn.org
Go to
Manage Jenkins → Manage Plugins
, under Available tab, search for ”GitHub pull request builder”Mark the checkbox and click
Install without restart
to installGo to builder.openwsn.org/restart and click
Yes
to restart Jenkins
Configure plugin
Go to
Manage Jenkins → Configure System
, inGitHub Pull Request Builder
setting, add the GitHub account into thecredentials
area. The GitHub account needs to have admin rights on the repository (pull/push is NOT enough).Click
Test Credentials...
button, verify you readTest basic connection to GitHub
Click
Connect to API
button, verify you read “Connected to https://api.github.com…”Check
Auto-manage webhooks
checkboxin the “admin list“, add the GitHub account
Leave the rest as default and click
Save
to save the settings
create new job
Click
New Item
to create a job, give a name of the job, selectFreestyle project
and then clickOK
to get in the jobconfigure
pageIn the
General
Tab, checkGitHub project
and put the repository url there, e.g. “https://github.com/changtengfei/dummy_test“In the
Source Code Management
Tab, selectGit
, put the same URL and leave the credentials as “none”Click the
Advanced…
button and put “+refs/pull/:refs/remotes/origin/pr/” in theRefspec
field. This tells the Jenkins job, when it runs, to retrieve the list of branches from the forked repo.In the
branches to build
section, enter “${sha1}” in thebranch Specifier
textfield. This tells Jenkins to merge in the branch specified in the PR.In the
Build Triggers
Tabcheck
GitHub Pull Request Builder
put the GitHub admin account in the
Admin list
fieldcheck the
use GitHub hooks for build triggering
check the
Build every pull request automatically without asking (Dangerous!)
leave the rest settings as default.
In the
Build Tab
put the test script you want the job to do after getting the code from the Pull Request.
In
Post-build Actions
, add any post actions you want after the build process is done.Click
Save
to save the settings.
Create webhook on GitHub
Log into your GitHub account, that must be an account with admin privileges to the repo
In the
Settings
tab of the repo, click onWebhooks
Click
Add webhook
, underWebhooks / Manage webhook
Put <https://openwsn-builder.paris.inria.fr/ghprbhook/> (“ghprbhook“ is a magic string identifying the GitHub PR build book plug) in the Payload URL
Select
Let me select individual events
and check the Pull Request and Push as the event to trigger the buildClick
Update webhook
to create the webhook
You should see the payload URL is the
Webhooks
list, with a green check mark.
Demo
repo: https://openwsn-builder.paris.inria.fr/job/dummy_test/
Jenkins job: https://github.com/changtengfei/dummy_test
GitHub Status images:
When Jenkins build passes, GitHub shows
When Jenkins build fails, GitHub shows