Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BitBucket WebHook Jenkins

I'd like to configure bitbutcket to trigger a jenkins build.

I've spent some time researching this and all the answers are from a few years ago, and have not found any guides because things seem to have changed since.

What I'm trying to do: A bitbucket push to a particular branch triggers a build.

What I've got: Bitbucket web hooks which fires HTTP request to Jenkins on a push to any branch. I've also installed the Bitbucket plugin on Jenkins which adds a check box in the job config Build when a change is pushed to BitBucket. This checkbox doesnt seem to work (maybe I set it up wrong? minimal docs for this), despite me pushing to the configured branch in the SCM section.

Problem 1: Bitbucket does not fire a GET, but another request which causes a 403. I tested with postman, and it works with a GET, but not a POST.

Problem 2: This HTTP build request is fired on pushes to any branch. While the build is still restricted to a particular branch, it seems unnecessary to be rebuilding all the time.

How do i address these issues? Bitbucket does not seem to be very flexible in customizing this. The Jenkins plugin for bitbucket has a lot of 'bad' reviews. How are developers currently doing this?

like image 705
OrangePot Avatar asked Aug 30 '17 23:08

OrangePot


1 Answers

SPECIFIC solution for Jenkins CI server--Webhook to Jenkins for Bitbucket plugin has been commercialized in latest version of Bit-Bucket and the current price is around $4800 which was earlier a free offering, because of this, guys who want to save their bucks, can go to the alternative solution by using webhooks feature of bit-bucket:-

Steps to create a webhook:-

BitBucket Side

1) Go to your bitbucket repo, click on Repository Setting, under WORKFLOW got for WEBHOOKS option and create a webhook.

a) creation of webhook:- URL https://JenkinsserverURL/git/notifyCommit?url=https://bitbucket.repository-link/repository.git

b) In the name tab, give any name of your choice

c) click on TEST CONNECTION before saving it. Make sure you get http status 200 d) View details your logs, check your request and response is correct.

Things to take care of from Jenkins Side:-

1) Make sure repository mentioned in bitbucket webhook is used in Jenkins job. 2) In SCM option, activate/select Poll SCM option, don't mention anything in the schedule, leave it blank. 3) configure rest job,

Whenever your git repo observes any change an automatic build will get triggered in Jenkins. By default push trigger is activated and if you want to activate other action, please select those events while creating webhook.

***to specify the branch in repository webhook:-

http://yourserver/git/notifyCommit?url=<URL of the Git repository>[&branches=branch1[,branch2]*][&sha1=<commit ID>]

Cheers,

like image 92
Rizwan Javid Avatar answered Oct 16 '22 06:10

Rizwan Javid