Integrate Jenkins With GitHub
This tutorial will show you how to integrate your Jenkins builds with GitHub so that your project builds when specific branches are pushed to (e.g. staging/production).
In Jenkins click configure on your project.
Then click on configure
Navigate down to Build Triggers and select GitHub hook trigger for GITScm polling.
- Scroll Down to Pipeline and enter your repository URL (I'm using git path as I'm authenticating with the use of an SSH key).
- Specify your credentials (preferably using a deploy key unique to this project).
- Click Add branch to add branches for each branch you wish to build for.
- Specify your branches that you wish to build for here. E.g. I have branches for staging and production.
Go to your GitHub repository and click on Settings, Webhooks, and then Add webhook.
- In the Payload URL field, paste the URL you built up in the earlier step.
- In the ‘Content type’ select: ‘application/json’
- Leave the ‘Secret’ field empty
- Just trigger the push event.
- Press the button to add the webhook.
Now when you push to your GitHub repository, it will prompt Jenkins to poll for changes and build staging/production if there are changes.
First published: 27th May 2021