Integrating Jobs on ci.centos.org with Github
We use the Github Pull Request Builder and Github plugins for handling the communication between Jenkins and Github Pull requests.
There are 2 basic workflows for triggering builds based on activity on Github:
1. Repo Setup
These steps are common no matter which mode you choose
When configuring a new job:
- Open the job config and select 'Github Project' under the General tab. Paste in the frontpage of your github repository.
For example, the CentOS t_functional test suite has a frontpage of https://github.com/CentOS/sig-core-t_functional
- Add your full git url under Source Code Management section
Continuing with the same example, you would use: https://github.com/CentOS/sig-core-t_functional.git
- Choose your trigger strategy (See Mode 1 or Mode 2 below)
If you're using Jenkins Job Builder to configure your jenkins jobs, here is a useful link to know how to do that : https://docs.openstack.org/infra/jenkins-job-builder/triggers.html?highlight=github#triggers.github-pull-request
2. Mode 1: Trigger on Every Commit
This mode simply triggers Jenkins jobs after someone has pushed to master (or another branch) on your Github repository.
After completing the Repo Setup steps:
In the 'Build Triggers' section, select 'Build when a change is pushed to GitHub'
Add a Webhook to your repository pointing at https://ci.centos.org/github-webhook/
- On your Github Project page, choose 'Settings'
- Navigate to the 'Webhooks and Services' tab
- Choose 'Add a webhook'
Paste 'https://ci.centos.org/github-webhook/' in the Payload URL
- Open the new webhook and verify the ping in the Recent Deliveries section
3. Mode 2: Trigger a build for each Pull Request
This mode requires a bit more setup, but can trigger on and report the status of a Jenkins job on each pull request
After completing the Repo Setup steps:
- On Github, add the 'centos-ci' user as a collaborator on your repository
This gives ci.centos.org commit access in order to set the test status on each pull request
- In your repository visit the Collaborators tab in the repo Settings
- Search by username 'centos-ci' and click 'Add Collaborator'
- Add the Github Pull Request Builder webhook
- On your Github Project page, choose 'Settings'
- Navigate to the 'Webhooks and Services' tab
- Choose 'Add a webhook'
- Select 'Let me select individual events' under 'Which events would you like to trigger this webhook?'
- Unselect 'Push' and select 'Pull Request' and 'Issue Comment'
Paste 'https://ci.centos.org/ghprbhook/' (note the trailing slash) in the Payload URL
- Open the new webhook and verify the ping the Recent Deliveries section
In the 'Build Triggers' section, Select 'GitHub Pull Request Builder'
- Add the github usernames of your team in the 'Admin List'
- Pull requests coming from Github users in the Admin List or the whitelist will automatically be tested in ci.c.o
- Pull requests coming from other users will need to be triggered in a comment on the PR using the trigger phrase (ex: 'dotests') by someone in the Admin list
- To pull the correct source code for each pull request we need to modify the SCM Section of the Jenkins job config
- Under 'Source Code Management' click 'Advanced' under the repository you added before
Add +refs/pull/*:refs/remotes/origin/pr/* for the refspec attribute
Under the 'Branches to Build' section add ${ghprbActualCommit}