Building projects based on pull request is something you cannot avoid in CI/CD pipelines. Nowadays every team does several deployments/operations per day and lots of builds have to happen in this process. Also, the teams work on the same repo collaborating code require faster code integrations. So it is better have an automated build process that kicks of the CI/CD pipeline on a pull request rather than manually triggering the jobs.
Trigger Builds Automatically On Github Pull Request
In this tutorial, we will explain how to configure a pull request based build trigger on Jenkins using Github webhooks and Github pull request builder plugin.
Install Github Pull Request Builder Plugin
- Go to
Manange Jenkins --> Manage Plugins
Click on the
availabletab at the top and search for
Github Pull Request Builder. Select the plugin using the checkbox and click
Install without restartas shown in the image below.
- Once the plugin is installed, select the restart checkbox as shown in the image below.
Github Pull Request Builder Configuration
Once Jenkins is restarted, follow the steps given below for configuring the plugin with your GitHub account.
- Head over to
Manange Jenkins --> Configure System
- Find “GitHub Pull Request Builder” section and click add credentials.
- Enter your Github username and password and add it.
- You can test the Github API connection using the test credentials button. It should show “connected” as shown below. Save the configuration after testing the API connection.
Github Repo Webhook Configuration
For Jenkins to receive PR events through pull request plugin, you need to add the Jenkins pull request builder payload URL in the Github repository settings.
- Go to Github repository settings, and under webhooks, add the Jenkins pull request builder payload URL. It has the following format
- Once saved, go back to the webhook option and see if there is a green tick. It means, Github is able to successfully deliver the events to Jenkins webhook URL.
Job Configuration for Automated Pull Request Builds
Lets get started with the build job configuration for PR plugin.
- Under general tab, select Github project option and enter the Github repo URL for which you want the PR builds without .git extension as shown below.
- Click advanced option and enable automatic PR build trigger and add the target branches you would raise the PR for.
- Add your pipeline build steps and save the configuration.
- Now raise a PR against the whitelisted branch you have given in the Jenkins PR trigger settings. You should see the job getting triggered on Jenkins.