Trigger Jenkins build when pull request is merged in Github

No need for webhooks anymore, since you now how GitHub Actions (assuming you are using, although the Actions are coming with GHE, GitHub Enterprise, in Beta, starting Sept. 2020).

As explained on this thread, you can trigger, on GitHub side, a job when a pull request is merged on master:

      - master
    types: [closed]

  <job id>:
    if: github.event.pull_request.merged == true
    steps: // the rest of the code

And that job can then use a GitHub Action like Trigger Jenkins Job for GitHub Actions, which will call your Jenkins and trigger one or several Jenkins jobs.


    name: Build
    runs-on: ubuntu-latest
    - name: trigger single Job
      uses: appleboy/jenkins-action@master
        url: ""
        user: "example"
        token: ${{ secrets.TOKEN }}
        job: "foobar"

After discussion with the OP and following the GitHub Actions tutorial, I confirm that:

  • Jenkins does not have to be started with Docker, it only has to be addressable from GitHub through its public URL;
  • The "trigger remote build" needs to be activated on Jenkins;
  • a token needs to be generated for the Jenkins user with the right to launch the Jenkins job;
  • A file triggerJenkinsBuild.yml (or any other name you want) must be created in the folder .github/workflows in your GitHub repository, with the two YAML sections mentioned above;
  • The "url:" field is just the base URL of the Jenkins instance, no extra path.

Tried looking everywhere, then figured out this solution myself

I'm assuming you've already configured webhook for jenkins, hence skipping that. The idea is to capture merge status and only trigger build if its true.

I'm using generic webhook trigger on jenkins and optional filters to achieve this.

This variable returns true if the build was merged.enter image description here

And the triggering the build only if this variable is true enter image description here