Jenkins: Kick off a CI Build with GitHub Push Notifications

When creating a Jenkins multi-branch pipeline job, builds will be triggered based on the rules set for each job. By default, each repository is scanned on a timer (e.g. every 30min, once a day) and builds are triggered if new commits or pull requests have been made since the last scan. However, what I really want is for my continuous integration builds to get kicked off immediately after someone opens a new PR or pushes a new commit.

I was initially stumped as to why this wasn't working - I had gone through quite a few GitHub setup steps when configuring Jenkins. My web searches didn't turn up anything obvious, but eventually I stumbled across a helpful Cloudbees article describing web hook configuration. Hopefully someone else who is stumped will find this helpful guide!

In order for builds to be triggered automatically by PUSH and PULL REQUEST events, a Jenkins Web Hook needs to be added to each GitHub repository or organization that interacts with your build server. You (or someone who can help) will need admin permissions on that repository.

Step-by-Step Guide

For each GitHub repository or organization that you need to configure, perform the following steps:

  1. Navigate to the "Settings" tab.
  2. Select the "Webhooks" option on the left menu
  3. Click "Add Webhook"
  4. For "Payload URL":
    • Use the address for the Jenkins server instance (e.g. http://myjenkins.com)
    • Add /github-webhook/ to the end of it.
    • Make sure to include the last /!
      • example: http://myjenkins.com/github-webhook/
  5. Select "application/json" as the encoding type
  6. Leave "Secret" blank (unless a secret has been created and configured in the Jenkins "Configure System -> GitHub plugin" section)
  7. Select "Let me select individual events"
    • Enable PUSH event
    • Enable Pull Request event
  8. Make sure "Active" is checked
  9. Click "Add Webhook"

Jenkins will now receive push and pull request notifications for that repository, and related builds will be automatically triggered.

Further Reading