Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - trigger build when Github PR is closed or merged

I am using Jenkins with Github pull request builder plugin

https://wiki.jenkins.io/display/JENKINS/GitHub+pull+request+builder+plugin

It's fine to trigger the build when the PR is open or update but I need a way to trigger when the PR is closed or merged.

I use Terraform to launch a bunch of servers so I need the event or condition to terminate the stack after the PR is closed/merged.

Seems like most of the plugins only be trigger by open/update event on Github PR.

Any idea?

Thank you!

like image 941
neo0 Avatar asked Oct 12 '17 10:10

neo0


People also ask

Can Jenkins build be triggered automatically?

Follow the steps as mentioned below to trigger a Jenkins job automatically based on GitHub's webhook configurations: Step 1: Go to the Configuration page of the respective job and under the build trigger section, check the "GitHub hook trigger for GITScm polling" checkbox and click on the Save button.

What happens when a pull request is merged?

Once the repository maintainer has approved a pull request, the developer's new updates in the forked repository are merged with the main project repository. The product is then updated with the new feature or bug fix, and can now be viewed by end users.

How do I trigger a Jenkins job on a pull request?

For Jenkins to receive PR events through the pull request plugin, you need to add the Jenkins pull request builder payload URL in the Github repository settings. If you need just the PR triggers, you can select the “Let me select individual events” option and select just the “Pull requests” option.


1 Answers

You can do so by two methods:

1) Either by a webhook. This requires your jenkins to have a public endpoint or some public endpoint (could be a proxy) via which github can post to your jenkins.

https://wiki.jenkins.io/display/JENKINS/GitHub+Plugin#GitHubPlugin-ManualMode

2) If a public endpoint is not available, then poll the repo every minute as a workaround.

http://www.andyfrench.info/2015/03/automatically-triggering-jenkins-build.html

Please note that in bigger setups, poll may have some performance implications. (I have been using it for years without any problems in smaller setups).

https://blogs.microsoft.co.il/leonj/2017/01/24/jenkins-poll-scm-the-nightmare-for-performance/

like image 77
Anshu Prateek Avatar answered Nov 01 '22 07:11

Anshu Prateek