This page explains how to integrate Jenkins builds into a GitHub workflow. In particular:
|
start:
an existing repo
a Jenkins machine
end:
one more job on Jenkins
GitHub repo linked
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 install
Go to builder.openwsn.org/restart and click Yes
to restart Jenkins
Configure plugin
Go to Manage Jenkins → Configure System
, in GitHub Pull Request Builder
setting, add the GitHub account into the credentials
area. The GitHub account needs to have admin rights on the repository (pull/push is NOT enough).
Click Test Credentials...
button, verify you read Test basic connection to GitHub
Click Connect to API
button, verify you read “Connected to https://api.github.com…”
Check Auto-manage webhooks
checkbox
in 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, select Freestyle project
and then click OK
to get in the job configure
page
In the General
Tab, check GitHub project
and put the repository url there, e.g. “https://github.com/changtengfei/dummy_test“
In the Source Code Management
Tab, select Git
, put the same URL and leave the credentials as “none”
Click the Advanced…
button and put “+refs/pull/:refs/remotes/origin/pr/” in the Refspec
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 the branch Specifier
textfield. This tells Jenkins to merge in the branch specified in the PR.
In the Build Triggers
Tab
check GitHub Pull Request Builder
put the GitHub admin account in the Admin list
field
check 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.
Log into your GitHub account, that must be an account with admin privileges to the repo
In the Settings
tab of the repo, click on Webhooks
Click Add webhook
, under Webhooks / 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 build
Click Update webhook
to create the webhook
You should see the payload URL is the Webhooks
list, with a green check mark.
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