Programster's Blog

Tutorials focusing on Linux, programming, and open-source

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).

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.


  1. 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).
  2. Specify your credentials (preferably using a deploy key unique to this project).
  3. Click Add branch to add branches for each branch you wish to build for.
  4. 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.


  1. In the Payload URL field, paste the URL you built up in the earlier step.
  2. In the ‘Content type’ select: ‘application/json’
  3. Leave the ‘Secret’ field empty
  4. Just trigger the push event.
  5. 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

Last updated: 27th May 2021
First published: 27th May 2021