{"id":894,"date":"2020-06-16T17:24:00","date_gmt":"2020-06-16T17:24:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=894"},"modified":"2020-06-16T17:24:00","modified_gmt":"2020-06-16T17:24:00","slug":"jenkins-build-trigger-github-pull-request","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=894","title":{"rendered":"Jenkins Automated Build Trigger On Github Pull Request &#8211; How To Guide"},"content":{"rendered":"<!--kg-card-begin: html-->\n<p class=\"wp-block-paragraph\">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. <\/p>\n\n\n<p class=\"wp-block-paragraph\">Also, the teams work on the same repo collaborating code require faster code integrations. So it is better to have an automated build process that kicks off the CI\/CD pipeline on a pull request rather than manually triggering the jobs.<\/p>\n\n\n<h2 class=\"wp-block-heading\">Trigger Builds Automatically On Github Pull Request<\/h2>\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, we will explain how to configure a pull request based build trigger on Jenkins using&nbsp;Github webhooks and Github pull request builder plugin.<\/p>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> Multipbranch Pipeline is the best way to achieve Jenkins pull request based workflow as it is natively available in Jenkins. Check out <a href=\"https:\/\/devopscube.com\/jenkins-multibranch-pipeline-tutorial\/\" target=\"_blank\" aria-label=\"this article on the multibranch pipeline (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">this article on the multibranch pipeline<\/a> for setup and configuration.<\/p><\/blockquote>\n\n\n<h3 class=\"wp-block-heading\">Install Github Pull Request Builder Plugin<\/h3>\n\n\n<ol class=\"cool-list wp-block-list\"><li>Go to<code> Manange Jenkins --&gt; Manage Plugins<\/code><\/li><li><code><\/code>Click on the <code>available<\/code> tab at the top and search for<code> Github Pull Request Builder<\/code>. Select the plugin using the checkbox and click <code>Install without restart<\/code>&nbsp;as shown in the image below.<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1445\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/screen-shot-2017-07-22-at-9-43-17-pm-1.jpg\" alt=\"github pull request builder plugin\" width=\"2836\" height=\"744\"><\/li><li>Once the plugin is installed, select the restart checkbox as shown in the image below.<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1448\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/screen-shot-2017-07-22-at-9-56-57-pm-1.jpg\" alt=\"jenkins plugin restart\" width=\"1290\" height=\"206\"><\/li><\/ol>\n\n\n<h3 class=\"wp-block-heading\">Github Pull Request Builder Configuration<\/h3>\n\n\n<p class=\"wp-block-paragraph\">Once Jenkins is restarted, follow the steps given below for configuring the plugin with your GitHub account.<\/p>\n\n\n<ol class=\"line-list wp-block-list\"><li>Head over to&nbsp;<code>Manange Jenkins --&gt; Configure System<\/code><\/li><li>Find &#8220;GitHub Pull Request Builder&#8221; section and click add credentials.<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2145\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/pr-builder-github-api-connectivity-1.png\" alt=\"Jenkins - Github connectivity\" width=\"2072\" height=\"508\"><\/li><li>Enter your Github username and password and add it. <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2147\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/jenkins-github-creds-1.png\" alt=\"jenkins - github credentials\" width=\"1838\" height=\"838\"><\/li><li>You can test the Github API connection using the test credentials button. It should show &#8220;connected&#8221; as shown below. Save the configuration after testing the API connection.<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2148\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/pull-request-builder-credentials-configuration-1.png\" alt=\"pull request builder credentials configuration\" width=\"2034\" height=\"1062\"><\/li><\/ol>\n\n\n<h3 class=\"wp-block-heading\">Github Repo Webhook Configuration<\/h3>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<ol class=\"line-list wp-block-list\"><li>Go to Github repository settings, and under webhooks, add the Jenkins pull request builder payload URL. It has the following format <pre class=\"lang:default decode:true \">http:\/\/&lt;Jenkins-IP&gt;:&lt;port&gt;\/ghprbhook\/<\/pre> <figure><img loading=\"lazy\" decoding=\"async\" width=\"1996\" height=\"780\" class=\"alignnone size-full wp-image-2150\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/gihub-jenkins-webhools-settings-1.png\" alt=\"github jenkins webhools settings\"><\/figure> <p>If you need just the PR triggers, you can select the &#8220;Let me select individual events&#8221; option and select just the &#8220;Pull requests&#8221; option. Save the webhook after selecting the required events.<img loading=\"lazy\" decoding=\"async\" width=\"1438\" height=\"1204\" class=\"alignnone size-full wp-image-2153\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/add-webhok-1.png\" alt=\"add webhook in github for jenkins\"><\/p> <\/li><li>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 the Jenkins webhook URL.<img loading=\"lazy\" decoding=\"async\" width=\"1986\" height=\"404\" class=\"alignnone size-full wp-image-2155\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/github-activated-webhook-1.png\" alt=\"github activated webhook\"><\/li><\/ol>\n\n\n<h3 class=\"wp-block-heading\">Job Configuration for Automated Pull Request Builds<\/h3>\n\n\n<p class=\"wp-block-paragraph\">Lets get started with the build job configuration for PR plugin.<\/p>\n\n\n<ol class=\"line-list wp-block-list\"><li>Under the 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.<img loading=\"lazy\" decoding=\"async\" width=\"1888\" height=\"792\" class=\"alignnone size-full wp-image-2158\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/jenkins-github-repo-url-1.png\" alt=\"jenkins github repo URL\"><\/li><li>Click advanced option and enable automatic PR build trigger and add the target branches you would raise the PR for.<img loading=\"lazy\" decoding=\"async\" width=\"1762\" height=\"916\" class=\"alignnone size-full wp-image-2160\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/pr-build-target-branches-1.png\" alt=\"PR build target branches\"><\/li><li>Add your pipeline build steps and save the configuration.<\/li><li>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.<\/li><\/ol>\n\n\n<h3 class=\"wp-block-heading\">Other Jenkins PR based Build Workflows<\/h3>\n\n\n<p class=\"wp-block-paragraph\">Github Pull request builder plugin is not actively developed as the same functionality is being provided by multi-branch pipelines and Github organisation project.<\/p>\n\n\n<p class=\"wp-block-paragraph\">There is also a <a aria-label=\"Generic Webhook Plugin (opens in a new tab)\" href=\"https:\/\/plugins.jenkins.io\/generic-webhook-trigger\/?ref=devopscube.com\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Generic Webhook Plugin<\/a> that can be used to trigger Jenkins jobs on a Pull Request.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Also, you can write custom API endpoints that accept Github webhooks and process PR requests to trigger Jenkins job remotely. Custom APIs help only when the native Jenkins functionalities are not providing the workflow you are looking for.<\/p>\n<!--kg-card-end: html-->\n<hr><p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/jenkins-build-trigger-github-pull-request\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jenkins Automated Build Trigger On Github Pull Request &#8211; How To Guide \u2014 DevOpsCube<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/jenkins-build-trigger-github-pull-request\/<\/p>\n","protected":false},"author":1,"featured_media":895,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-894","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=894"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/894\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/895"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}