Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Jenkins Job from Bitbucket on Pull Request

Hoping to gather insight from professionals. My end goal is to trigger a jenkins build whenever a bitbucket pull request happens. If anyone could give me an ELI5(explain like I am 5) answer it would be greatly appreciated. Sorry if this is the wrong format, I am new to jenkins and stackoverflow.

What I have done so far:

  1. Created webhook in bitbucket and gave the url to my jenkins job. example: http://jenkinsURL:8080/job/boulevard-dev/generic-webhook-trigger/invoke?token=myPull_Request_Token

  2. Pull request webhook trigger

  3. In Jenkins, under source code management I have: Source Code Management Settings. This is currently fetching a ton of branches, failing, then building the master branch when the job starts?

  4. For build triggers, other stackoverflow articles have pointed me to the "Generic Webhook Trigger". https://github.com/jenkinsci/generic-webhook-trigger-plugin

  5. I am not entirely sure how this generic webhook trigger should effectively be setup? Hoping someone has experience using it and could explain what is needed.

  6. This is what have seen referenced in other articles.Build Triggers settings Build triggers settings 2

Questions:

  • What does a correct setup / example of the generic webhook trigger look like?
  • Currently, my job triggers when a change is made to master or merged to master, how can I specify to my job that I want the bitbucket pull request branch to be built?
  • Also, I found this, not sure if its related to my issue or not? https://jira.atlassian.com/browse/BCLOUD-5814
like image 766
Showler Avatar asked Jan 08 '20 20:01

Showler


People also ask

How do I trigger a Jenkins job on a pull request?

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. If you need just the PR triggers, you can select the “Let me select individual events” option and select just the “Pull requests” option.

Is there a plugin for Jenkins that triggers builds on Bitbucket?

Plugin for Jenkins v2.138.2 or later, that triggers builds on Bitbucket's push and pull requests events. The new features introduced by Bitbucket Push and Pull Request 2.x.x are:

How to trigger Jenkins job on pull request?

There is also a Generic Webhook Plugin that can be used to trigger Jenkins jobs on a Pull Request. Also, you can write custom API endpoints that accept Github webhooks and process PR requests to trigger Jenkins job remotely.

How to setup pull request trigger from Bitbucket?

(i) Add your bitBucket repo and branch to source code management (ii) On build Triggers setup Poll SCM to * * * * * for run every minute to check pull request from bitBucket. (i) Go to settings and add a new hook, now setup pull request trigger as per your requirement.

What is requests requirement in Jenkins?

Requirement is like : On Pull request raised from the BitBucket , that should build a trigger on jenkins Note , we need on multi-branch pipeline job. Please provide how to set up whole thing with respect to the Bitbucket and the Jenkins .


1 Answers

As per your requirement, you can trigger a Jenkins build whenever a bitbucket pull request happens by following the below steps, in my case, it's working fine.

Step(1) - Configure Jenkins
(i) Add your bitBucket repo and branch to source code management enter image description here (ii) On build Triggers setup Poll SCM to * * * * * for run every minute to check pull request from bitBucket. enter image description here

Step(2) - configure Bit Bucket Hook
(i) Go to settings and add a new hook, now setup pull request trigger as per your requirement. enter image description here

Step(3) - Make a pull request and see the new job automatically triggered on Jenkins. enter image description here

like image 114
Rahul Gaikwad Avatar answered Sep 30 '22 07:09

Rahul Gaikwad