title: Trigger Jenkins build when pull request is merged in Github
body: <p>This should be an easy, out-of-the-box configuration in Jenkins but I haven't found anything straightforward on the internet. All I want to do is a trigger a build ONLY when a pull request i merged in our Github repo.</p>
  <p>To start with, Github aggregates almost all activity around the pull request into one webhook (versus bitbucket which allows you to differentiate between actions).</p>
  <p><a href="https://i.stack.imgur.com/jm3fm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jm3fm.png" alt="enter image description here" /></a></p>
  <p>On the Jenkins side I've seen posts point towards the <a href="https://github.com/jenkinsci/generic-webhook-trigger-plugin" rel="noreferrer">Generic Webhook Plugin</a> which allows you to ingest the json of the webhook and create variables, however from here it looks like those need to be used in a script in order to trigger/not trigger a build.</p>
  <p><a href="https://plugins.jenkins.io/ghprb/" rel="noreferrer">Github Pull Request Build</a> is another popular plugin, but again there is nothing explicit that states &quot;only trigger this build when a PR is merged&quot; or even seems to give the option of looking for a specific value in the webhook json.</p>
  <p>Unless there are other plugins out there I haven't found the best option (i.e. least configuration to just get the build started) is to configure the GitHub hook trigger for GITSCM polling in Jenkins and on the Github side send the webhook only on push events... however this isn't the <em>exact</em> behavior we're looking for.</p>
  <p><a href="https://i.stack.imgur.com/pnDvw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pnDvw.png" alt="enter image description here" /></a></p>
  <p>Right now this is all being done via the UI, and it's been awhile since I've used Jenkins so maybe the declarative pipeline infrastructure has passed the UI by, but it seems like this should be much more intuitive. Can someone explain the easiest implementation they've found, using Jenkins and Github, to trigger a build ONLY when a pull request is merged to a specific branch?</p>