Jenkins and GitHub Pull Requests integration¶
Archived (pre-2022)
Preserved for reference only -- likely outdated. View original | Last updated: September 2020
Prerequisites¶
- Jenkins server must have credentials with appropriate access to the github repo you want to integrate with. Currently we use fyber-ci Jenkins user. Other creds can be added. More on credentials: ghprb-plugin (Github)
Job configuration¶
The following is example of Job integrated with GitHub PRs:
def configFile = readFileFromWorkspace('config/jenkins/dsl/config/parameters.groovy')
def env = System.getenv("JAC_ENVIRONMENT")
def config = new ConfigSlurper(env.toLowerCase()).parse(configFile)
pipelineJob(config.projectName + '-test-job') {
properties {
githubProjectUrl('https://github.com/SponsorPay/chef/')
}
definition {
cpsScm {
scriptPath('Jenkinsfile-test')
scm {
git {
branch('${sha1}')
remote {
name('origin')
url(config.gitUrl)
credentials(config.credentialsId)
refspec('+refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/*')
}
}
}
}
}
triggers {
githubPullRequest {
admins(['mykhailoguk', 'ddenyshchenko', 'slobodyanyuk'])
cron('H/5 * * * *')
triggerPhrase('.*(re)?run tests.*')
useGitHubHooks()
extensions {
commitStatus {
context('Jenkins')
}
buildStatus {
completedStatus('SUCCESS', 'Chef tests passed.')
completedStatus('FAILURE', 'Chef tests have failed.')
completedStatus('ERROR', 'An error occurred in Chef tests.')
}
}
}
}
}
You can find this job in our Jenkins here: Jenkins - testsuite-test-job
Webhooks¶
If Jenkins pooling not an option you can use GitHub web hooks for triggering Jenkins builds.
Web hooks must be created manually since Jenkins system user that we use for GitHub integrations doesn't have Admin rights.
GiHub project web hooks configuration:

Please reach out BLN DevOps to obtain shared secret for web hooks.
The web hook must have the following events enabled:

Once enabled GitHub will produce web hook logs that you can find at the very bottom of the web hook config page:

If job is configured properly you will see Jenkins job triggering in PR status:

References¶
For more detailed information please visit GitHub Pull Request Builder Plugin project: ghprb-plugin (Github)