Jenkins and github integration using webhooks
Reading Time: 2 minutes
As github has deprecated service integration feature, I had to reconfigure jenkins integration using webhooks. As this is not straightforward to do, this blog post will help you to save some time if you are using github/jenkins integration.
Jenkins github plugin.
Github Personal Access Token.
Lets go down the rabbit hole. You first need to create github personal access token for user that has access to github repository. In my case, that was my github account.
- Click on your github avatar
- Select Settings
- Select Developer Settings
- Select Personal Access Token
- Enter your github password
Hmmm, possible github UX issue, this is 4th level depth to get to this feature. Step 5 shows that github knows web security.
- Click generate new token
- Enter meaningful name
- Select permissions: admin:repo_hook, repo
- Generate token
- Copy token. Be careful, this is your only chance to copy it.
Again, proof that github understands web security.
Jenkins Global credentials
Using github token, you will create jenkins global credential.
- In jenkins, click credentials
- Click global (any of provided links)
My note on jenkins UX. Its free, and I understand that team do not have much resources. But credentials UX is really messed up.
- On left, click Add credentials
- For kind select secret text
- For scope leave Global option
- In secret, paste github token.
- Enter meaningful description. Trust me, this is very important, otherwise you will not be able to select this credentials.
Jenkins Github settings
- Manage Jenkins
- Configure System
- Scroll down to Github settings
- Add github server
- Set meaningful name
- Leave default API url
- Select credentials created in previous step.
- Click apply
- Click test connection. Following message should appear: Credentials verified for user xxx, rate limit: 4998
Note rate limit. You have 5000 requests per hour for all github integrations, not just Jenkins.
Github repository webhook
- Go to github repository that you are integrating with Jenkins. You need to have admin rights for that repo.
- Click Settings
- Select webhooks
- Add webhook
- Payload url is jenkins_url_with_http_or_https/github-webhook/
- Content type: application/json
- Just push event if you only want to trigger jenkins jobs by branch pushes.
- Check Active
- Click update
- Recent deliveries should have green check icon.
If that is not the case, click on latest delivery that will contain HTTP request/response.
Jenkins job build trigger.
- Go to your jenkins job
- In Build Triggers section, check out: GitHub hook trigger for GITScm polling
- Commit something to your repo in branch for which job is configured.
- Job should start executing.
I used those two in order to decript all steps in proper order:
Originally published at blog.tentamen.eu on June 23, 2018.