10

I need to integrate BitBucket with Jenkins, so that whenever a PR is opened in BitBucket, it will trigger a build in Jenkins. Can someone help describe the exact configuration step that I should follow in BitBucket and Jenkins to achieve this?

This is my configuration so far:

enter image description here

3 Answers 3

9

You can install 'Bitbucket Server Webhook to Jenkins' in Bitbucket. https://marketplace.atlassian.com/plugins/com.nerdwin15.stash-stash-webhook-jenkins/server/overview

Once install you will need to enable the 'Post Receive' Hook on the required repository.

Remember to enable 'poll SCM' for the Jenkins Job.

Update You can test the configuration of the plugin here: enter image description here

4
  • Thanks for infor Kyle... I tried the way you suggested but still its not working.. (I am using jenkins version 2.34) .
    – kumar
    Mar 30, 2017 at 16:16
  • Installed Post Receive Web hook on particular repo.. Entered the URL (p-gp2-apjsjenkins-1.imovetv.com/bitbucket-hook) & Enabled it (I am using jenkins version 2.34) .
    – kumar
    Mar 30, 2017 at 16:27
  • 1
    Hi Kumar, Can you provide me with more information on the error you are receiving or the console output you are receiving? Mar 30, 2017 at 17:05
  • 1
    Hi Kyle.... The build triggering successfully when there is open pull request.. at the same time its also triggering for scm changes to that repo...
    – kumar
    Apr 3, 2017 at 17:59
4

This is how I've setup my BitBucket Pull Requests Builder.

Pull Request Builder Example

CRON

Use * * * * * and it will poll BitBucket every minute to check for PRs.

Credentials

Setup a shared credential that you can use amongst all projects.

Repo Owner & Name

You should take the data from your repo URL/SSH like:

[email protected]:REPO_OWNER/REPO_NAME.git

Branches Filter

You can choose to only build specific branches or leave it blank to build all.

CI Identifier & Name

I set this as the name of our CI account we setup on BitBucket. If you create a new BitBucket account just for your pull requests, grant permission to the repositories that it needs. Then whatever username you set that new account to have enter it as the CI Name and CI Identifier.

Finally, leave the bottom two options ticked.

That's the settings that work for us.

1
  • 1
    The way you suggest working fine.. But the build also triggered whenever there is changes happened to bitbucket...
    – kumar
    Apr 3, 2017 at 17:00
0

We were able to achieve this using Jenkins multibranch pipeline, upon pull request creation and update pipeline would create a new job. It'll check out the pull request so we can build / run unit tests / sonarqube analysis on it.

Refer following for step by step guide, https://www.whatsuptec.com/trigger-jenkins-pipeline-on-bitbucket-pull-request/

1
  • Please add the steps that are required to prevent that these will be lost if the URL gets deprecated.
    – 030
    May 15, 2020 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.