Bitbucket Plugin for Jenkins

Build Status Jenkins Plugin GitHub release Jenkins Plugin Installs

About

Bitbucket plugin is designed to offer integration between Bitbucket and Jenkins.

It exposes a single URI endpoint that you can add as a WebHook within each Bitbucket project you wish to integrate with. This single endpoint receives a full data payload from Bitbucket upon push (see their documentation), triggering compatible jobs to build based on changed repository/branch.

Since 1.1.5 Bitbucket automatically injects the payload received by Bitbucket into the build. You can catch the payload to process it accordingly through the environmental variable $BITBUCKET_PAYLOAD.

Bitbucket Cloud usage

Configure your Bitbucket repository with a Webhook, using URL JENKINS_URL/bitbucket-hook/ (no need for credentials but do remember the trailing slash).

The older-style HTTP POSTs from Bitbucket are also supported but deprecated.

On each push, the plugin:

  1. Scans Jenkins for all jobs with "Build when a change is pushed to Bitbucket" option enabled. For MultiBranch pipelines Scan Multibranch Pipeline Triggers should be configured in order to be able to process the WebHook.
  2. For each job matched:
    1. If the job's SCM (git) URL "loosely matches" that of the git repository listed inside the Bitbucket-provided payload, AND
    2. If the job's SCM (git) detects that the remote repository has changes, THEN
    3. A full build of the job will be queued

The "loose matching" is based on the host name and paths of the projects matching.

Bitbucket server usage

Since the version 1.1.7 of the Bitbucket plugin works against Bitbucket server. For this plugin to work against Bitbucket server you must: 

  1. Install Post Webhooks for Bitbucket at Bitbucket side [the plugin is free]
  2. At repository level, delete the webhook in case it exists

  1. Create a Post-WebHook, which is different from WebHook and enable on push.

After this, you are all set-up

Override Repository URL

In case the matching mechanism does not work, you can manually override the URL used for matching.
For example:
The URL https://bitbucket.org/tzachs/my_repo.git.git would be tried to matched with https://bitbucket.org/tzachs/my_repo.git. This of course would fail.
To overcome this, setting the "Override Repository URL" field to https://bitbucket.org/tzachs/my_repo.git would match the URL and will trigger the JOB when a commit is pushed to my_repo.git.git

Job DSL

The current supported dsl is as follows:

freeStyleJob('test-job') {
  triggers{
    bitbucketPush()
  }
}

Job DSL example for overrideUrl

triggers{
  bitbucketPush overrideUrl: 'https://bitbucket.org/blabla/hello-world-server'
}

Changelog

250.v8032f588d8a_c

  • JENKINS-69490 - fixed NPE when using pipeline-syntax properties: Set job properties

237.vc424f493c5f6 (10. Dec 2023)

  • JENKINS-72448 - Updated jenkins.version from 2.375.3 to 2.414.1

223.vd12f2bca5430 (26. Feb 2022)

  • JENKINS-41635 - fixed. This required a change in Jenkins minimum version from 2.204.1 to 2.303.1

215.vfe32d14d1f47 (04. Feb 2022)

  • Fixed NPE

1.1.30 (20. Nov 2021)

  • JENKINS-49414 - Added ability to trigger the job upon receiving a branch was created event

1.1.29 (27. May 2021)

1.1.28 (19. May 2021)

  • JENKINS-65651 - Added option to override URL in multi branch jobs

1.1.27 (11. October 2020)

  • Fixed logging printing

1.1.26 (10. October 2020)

  • Added logging for JENKINS-63848

1.1.25 (8. September 2020)

1.1.24 (31. August 2020)

1.1.23 (29. August 2020)

1.1.21 (28. August 2020)

1.1.20 (12. August 2020)

1.1.19 (08. August 2020)

  • Added ability to override Repository URL which used for matching

1.1.18 (04. August 2020)

1.1.17 (04. August 2020)

  • Changed repos to use HTTPS as suggested by JLLeitschuh in PR #70

1.1.16 (30. July 2020)

  • Fixed spotbugs errors

1.1.15 (29. July 2020)

  • Fixed javadoc error preventing from releasing 1.1.14

1.1.14 (Not released)

  • Fixed CVE-2020-5529
  • Updated to jenkins version to 2.204.1

1.1.13 (26. July 2020)

  • See PR-75, supporting repos that end with .git

1.1.12 (Not released)

1.1.11 (27. August 2019)

  • Added possibility to process trigger from bitbucket server default webhooks PR-63 

1.1.10 (4. July 2019)

  • Update job-dsl dependency to 1.66. See PR-58 

1.1.9 (1. Jun 2019)

1.1.7 (6. Dec 2017)

  • Add Jenkins ci integration
  • JENKINS-28877 : Add integration for Bitbucket server

1.1.6 (2. Nov 2017)

1.1.5 (26. Jan 2016)

  • fix JENKINS-32372 Inject the Payload into the build through $BITBUCKET_PAYLOAD

1.1.4 (28. Dec 2015)

1.1.3 (16. Oct 2015)

  • fix JENKINS-29096 Advice users when they don't use the right hook url - last `/`
  • fix JENKINS-30985 Jobs with the same git repository defined several times in the scm should be triggered only once

1.1.2 (4. August 2015)

1.1.1 (9. July 2015)

  • Allow Webhooks 2.0

1.1.0 (10. March 2015)

  • fix JENKINS-24999 Build triggered by SCM change without activating trigger in the job configuration
  • fix JENKINS-26413 BitBucket trigger doesn't need to Initialize LogFile
  • fix JENKINS-26489 Action report for the bitbucket polling log on web UI
  • fix JENKINS-26805 Job is not triggered after merging a branch

1.0

  • initial implementation