Integrate Jenkins Pipeline Project With GitHub
This tutorial will show you how to integrate your "pipeline" Jenkins project with GitHub so that your project builds when specific branches are pushed to (e.g. staging/production).
Steps
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 by setting up and 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.
Conclusion
Now when you push to your GitHub repository, it will prompt Jenkins to poll for changes and build staging/production if there are changes.
References
- Blaze Meter - How to Integrate Your GitHub Repository to Your Jenkins Project
- How to trigger Multibranch Pipeline build with github webhook
Last updated: 29th June 2021
First published: 27th May 2021
First published: 27th May 2021