How to make Jenkins pipeline jobs triggered by pull requests for Apache projects
By: Vincent Hou
Tags: Pull Request, Apache Openwhisk, Jenkins, Apache, Jenkins Pipeline

This tutorial will walk through all the steps you need to follow, in order to set up Jenkins pipeline triggered by pull requests automatically for an Apache project such as Apache OpenWhisk. As an Apache project, no matter it is graduated or incubated, it is hosted in Github, and must be put under https://github.com/apache/. We will use Apache OpenWhisk as an example. The Github URL is https://github.com/apache/incubator-openwhisk. All the Jenkins jobs of Apache projects can be accessed and configured at this link: https://builds.apache.org/. Make sure you ask the Apache infrastructure team for the correct permission to Jenkins, in order to add and configure pipelines.

Apache has already install the Jenkins plugin GitHub pull request builder plugin, which is also be the plugin for us to configure the pipeline. I am sure you can find plenty of instructions about this plugin or Jenkins jobs kicked-off by pull requests, searching with any famous engines. However, they do not cover any configurations especially for Apache projects. Your pipeline would not be triggered automatically by the pull request, if you followed exactly what they’d said. Luckily, you will find them in this tutorial, so that you won’t waste your time reading it. It is possible that you have particular configurations for your pipeline, but I will only explain the necessary steps for you to kick-off your pipeline automatically by pull request for Apache projects.

Create a Jenkins pipeline

Visit the link https://builds.apache.org/, and login with your credentials. This is the page you will see:

Click on “New item” on the left panel.

Choose the pipeline, give it a name, and clink on the ‘OK’ button at the bottom.

You will be directed to the configuration page of this pipeline.

Configure your pipeline

On the General tab, you may give some description about his pipeline.

On the Datalog Tagging tab, check “GitHub project”, and put your project URL in the field.

On the Build Triggers tab, check “GitHub Pull Request Builder”. Then the GitHub API credentials is automatically filled in. Make sure the Admin list is filled in with at least one admin name. For my project, I put asfgit, which you can use as well for Apache projects. Check “Use github hooks for build triggering” below.

Next step is a crucial step: click the Advanced button to extend further options.

You can see Skip build phrase and Crontab line are automatically filled in. You can leave them as they are. You job here is to fill in the field “List of organizations. Their members will be whitelisted.” with apache. If you miss it, I am sure the PRs submitted by any Apache committer to your project will not kick-off the pipeline. It took me over 24 hours to find out this configuration, so take it.

On the Pipeline tab, set Definition to Pipeline script from SCM, and set SCM to Git. Under Repositories, set Repository URL to your Apache project. For OpenWhisk, it is git://github.com/apache/incubator-openwhisk.git. Set the Name to origin, and the Refspec to +refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/*. Under Branches to build, set the Branch Specifier to ${sha1}.

At last but not least, configure the Script Path to the Jenkinsfile. By default, this file is saved under the home directory of your Apache project, but you may put somewhere else, as long as you configure your script path pointing to it. After you click on the OK button, you are all set.

Now it is your job to implement your pipeline build in this Jenkinsfile.