9

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
Showler
  • 93
  • 1
  • 1
  • 4
  • This question is not about a coding problem, but will likely be well received at devops.stackexchange.com – guido Jan 09 '20 at 08:47
  • maybe I am a bit late to this question, but you can look [here](https://plugins.jenkins.io/bitbucket-push-and-pull-request/) and see if it works for you. – DroidDev Sep 14 '20 at 11:14

1 Answers1

9

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

Rahul Gaikwad
  • 563
  • 4
  • 9
  • 26
  • 1
    Rahul, is it possible to only build the pull request branch whenever the pull request is created? I see that in this example, it looks like Jenkins will only be building the master branch. – Showler Jan 09 '20 at 15:42
  • 1
    @Showler You can add any of your branch in Jenkins Configuration. Goto Source Code Management and in "Branches to build" option, enter your branch name in place of */master. – Rahul Gaikwad Jan 10 '20 at 13:38
  • @Showler You could use a regex to exclude the `master` branch see https://stackoverflow.com/a/18709097/1335793 – Davos Oct 05 '21 at 11:02
  • 1
    @RahulGaikwad seems like your configuration is to build only after merge, which does not require a webhook in BB, jenkins poll SCM alone should do it. Can you please check if build runs on PR creation or PR update as well. – Vinay Taneja Apr 04 '22 at 06:42