...
Info |
---|
This page explains how to integrate Jenkins builds into a GitHub workflow. In particular:
|
...
one more job on Jenkins
GitHub repo linked
Create token on GitHub
Log into you GitHub account, that must be an account with admin privileges to the repo
Go to “Settings” of your GitHub account, then go to “Developer settings->Personal access tokens“
Click “Generate new token“ and Select the following scopes:
repo
repo:status
repos_deployment
public_repo
admin:repo_hook
write:repo_hook
read:repo_hook
Give a name of the token in the “Note“ field and Click “Generate token“
The token will show up under the “Personal access tokens“ page, click “copy” button to copy the token to somewhere temporal. When it’s set in the target application, remove delete the token from anywhere else.
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 on “Webhooks”
Click “Add webhook”, under “Webhooks / Manage webhook”
Put <https://openwsn-builder.paris.inria.fr/github-webhook/> (“github-webhook“ is a magic string identifying the GitHub plugin) in the Payload URL
Select “Let me select individual events“ and check the “Pull Request”, “Push” and “Repositories” 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.
Create Job on Jenkins
install plugin
Log into builder.openwsn.org
Go to Manage “Manage Jenkins → Manage PluginsPlugins”, under Available tab, search for ”GitHub pull request builder”Mark the checkbox and click
Install without restart
Branch Source”, mark the checkbox of the pluginsearch for ”SCM Filter Branch PR” and mark the checkbox of the plugin
click “Install without restart” to install
Go to builder.openwsn.org/restart and click
Yes
“Yes” to restart Jenkins
Configure plugin
Go to Manage Jenkins → Configure System, in
GitHub 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
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.Click
New Item
“New Item” to create a job, give a name of the job, selectFreestyle project
“GitHub Organization” and then clickOK
“OK” to get in the job configure pageIn the
General
“Projects” 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 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.
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.
Create webhook on GitHub
in the “GitHub Organization“ section, Click “Add” next to “Credentials“
Select the option with the job name
In “Kind“ text box, select “Username with password“
In “Username“ text box, write down the GitHub account name
In “Password“ text box, write down the token created in section above
Click “Add“ to return to the “configure“ page
In the drop box of “Credentials“, select “[accoutname]/**********“
In the “Owner“ text box, type down the GitHub Account/Organization name. This allows the Job to read the related branches/PR associated with the account/organization
In the “Behaviors“ part, click the “Add“ button at bottom to add the following configurations:
Repositories
“Filter by name (with wildcards)”, using “Include“/”Exclude” to filter the repository you want the job to hook
Within repository
“Discover branches“, select “Strategy“ as “Exclude branches that are also filed as PRs“
“Discover pull requests from forks“, select “Strategy“ as “Merging the pull request with current target“, select “Trust“ as “Everyone“
“Filter by name including PRs destined for this branch (with wildcards)“, type down “master“ in “ Branch Include” text box
In the “Project Recongnizers“ part, write down the Script path to the “Jenkinsfile“, which contains the Pipeline script that the Job should run
In “Scan organization triggers“, uncheck the “Periodically if not otherwise run“
In “Child Scan Triggers“, uncheck the “Periodically if not otherwise run“
Click “Apply“ then “Save” to complete the settings.
Create Jenkinsfile in Repository
The Github Organization job uses Pipeline as the build action to run.
The Pipeline script lives in the repository with name “jenkinsfile”. Following is an example what the Pipeline script looks like.
Code Block |
---|
pipeline {
agent {
label 'windows && a102'
}
stages {
stage('Test') {
steps {
bat 'pytest --junitxml=report.xml'
}
}
}
post {
always {
junit 'report.xml'
}
}
} |
Demo
repo: https://openwsn-builder.paris.inria.fr/job/dummy_test/github.com/changtengfei/demo_github_jenkins_repo
Jenkins job: https://github.com/changtengfei/dummy_test openwsn-builder.paris.inria.fr/job/testdemo/
GitHub Status images:
When Jenkins build passes, GitHub shows
When Jenkins build fails, GitHub shows
Related
https://wiki.jenkins.io/display/JENKINS/GitHub+pull+request+builder+plugin+Branch+Source+Plugin
https://wiki.jenkins.io/display/JENKINS/SCM+Filter+Branch+PR+Plugin
...