Jenkins pipeline trigger on merge to master

2.7k views Asked by At

I want to setup Jenkins pipeline trigger when PR is merged to master branch. I have setup Webhook in GitHub repo pointing to Jenkins url http://jenkins.example.com:8080/github-webhook/ and selected following events

  1. Pull request review comments
  2. Pull request reviews
  3. Pull requests

in my Jenkinsfile I use this

 triggers {
     pullRequestReview(reviewStates: ['approved'])
 }

But it failed with this error

WorkflowScript: 6: Invalid trigger type "pullRequestReview". Valid trigger types: [upstream, cron, parameterizedCron, GenericTrigger, githubPush, pollSCM] @ line 6, column 9.

If I want to trigger the build when PR is merged to master, what I should user in triggers ?

1

There are 1 answers

0
AudioBubble On

Here is what you need:

      GenericTrigger(
              genericVariables: [
                      [key: 'action', value: '$.action'],
                      [key: ‘merged, value: '$.pull_request.merged]
              ],

              causeString: 'Triggered on pr merge,

              token: ‘<your-token>’,

              printContributedVariables: true,
              printPostContent: true,
              silentResponse: false,
              regexpFilterText: '$action#$merged,
              regexpFilterExpression: ‘closed#true'
      )
  }

And you don't need to select Pull request review comments and Pull request reviews events. Just Pull requests is enough for this case.