Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up a github pull request build in a Jenkinsfile?

So, I've been using Jenkins for quite a while. I have set up numerous projects with the Github Pull Request Builder plugin to run tests whenever someone opens a pull request, and then trigger some other job (build, push, deploy, etc) whenever the pull request actually gets merged to master.

So, is there any way to set this up with a Jenkinsfile, or the organization folders, or the multibranch build deal?

like image 472
Paul Becotte Avatar asked Jun 06 '16 15:06

Paul Becotte


1 Answers

The github-organization-folder plugin in combination with the multi-branch plugin plugin offers exactly this awesome feature: It scans a whole organization (optionally restricted to certain patterns in repo/branch names) for Jenkinsfiles and automatically adds jobs. This also happens for Pull Requests.

Once the PR is closed, it automatically removes the job.

To avoid arbitrary code execution, an organization member has to trigger building the job (same as for the GPRB plugin). The phrase can be configured in the Jenkins System settings.
EDIT: Under the Advanced section in Jenkins, you find options about what types of PR you want to build. If you build fork PRs, then there's afaik no way to prevent running code without prior inspecting it.


An example, how this looks like:

PR on Github


PR in Jenkins

like image 178
StephenKing Avatar answered Nov 10 '22 18:11

StephenKing