Triggered Hook based on Pull Request on Jenkins

I have done POC on triggering Jenkins Job based on pull request from the source branch so I just want to guide you through the process I have followed to implement it. Hopefully, It will help someone who got stuck on achieving this configuration.

Let’s start !!!

Step 1

First thing first you need to have access token of Github, create it from developer settings. If you’re not aware of it do google search.

We will create the repo with the name pr-test. From the setting of your repo configures webhook.

Step 2

Log in to the Jenkins and configure it by going to Manage Jenkins and then Configure System. Afterward, follow the configuration in the below image.

Note: You need to create credentials first so for that go to the credentials section of jenkins and add credentials, make sure to add credential in secret text section. Once you will select secret text you need to pass your github token for authentication.

Note down the credential Id we will need it later in our further configuration.

Important

Step 3

Create Jenkins Pipeline Job with below configuration and Pipeline Script from Step 4.

Step 4

Most Important configuration of GitHub to trigger the job of only source branch from which PR request raised.

Step 5

Create one branch in the repo, In that branch create one file with the name “test”, Now raise a PULL REQUEST, once done the job will automatically get a trigger for the branch you have created.

That’s it, any queries or suggestion feel free to comment below.

Askops
Askops
Developer: Nikhil raj
Price: Free

Leave a Reply