Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (29.3k points)

I'd like to configure bitbucket 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 webhooks which fires HTTP request to Jenkins on a push to any branch. I've also installed the Bitbucket plugin on Jenkins which adds a checkbox in the job config Build when a change is pushed to BitBucket. This checkbox doesn't 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 the 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?

1 Answer

0 votes
by (19.4k points)

Check whether your Jenkins URL accessible from your Bitbucket server? If yes that it should be fairly simple to do it. You add the webhook in your repository as 

http://<url-of-jenkins>/git/notifyCommit?url=<url-of-repository>

When Jenkins receives this POST, it automatically triggers builds on those jobs that use this git repo with that URL you give in webhook.

But you also need to make sure your Build Schedule is set to empty for those jobs. otherwise, it won't get triggered. You can specify a branch in webhook URL too

See the Push Notification from the repository here: https://wiki.jenkins.io/display/JENKINS/Git+Plugin

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...