Skip to end of metadata
Go to start of metadata

Plugin Information

View Bitbucket on the plugin site for more information.

This plugin is currently looking for more maintainers.


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
  2. Each 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

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


After this, you are all set-up

Job DSL

The current supported dsl is as follows:

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

Changelog

 

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 InitializeLogFile
  • 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


  • No labels

39 Comments

  1. Hello,

     First off thanks for taking a stab at this, but I do have a few questions.  It's not clear how you expect this to work, and what expectations you are making.  If I have a repo on bitbucket called "provisioning" and I have jobs for each branch: ( provisioning-14, provisioning-13, provisioning-12 ) how does this plugin know which job to trigger? 

    -John

  2. Hello,

     First off thanks for taking a stab at this, but I do have a few questions.  It's not clear how you expect this to work, and what expectations you are making.  If I have a repo on bitbucket called "provisioning" and I have jobs for each branch: ( provisioning-14, provisioning-13, provisioning-12 ) how does this plugin know which job to trigger? 

    -John

  3. Hello,

    Member of the Atlassian Bitbucket team here. We already have working integration with Jenkins provided by our Jenkins Hook. It supports all the forms of security built-in to Jenkins and has been tested thoroughly. This plugin shouldn't be necessary to get Jenkins to build using a Bitbucket push.

    Cheers,

    Marcus Bertrand

    EDIT: this comment is no longer accurate or current.

    1. Marcus - We have never had any luck using your plugin.  At this point I got this one working and I dont see myself changing any time soon.  

      1. Hi John,

        We have tested the integration between Bitbucket and Jenkins in a variety of methods. Please open a support request to support@bitbucket.org and we will be happy to assist you in getting it working.

        EDIT: This comment is no longer accurate or current.

    2. Marcus,

      Your Jenkins Hook does not allow one to specify which branch to build, so it's essentially useless.

      Further, it's the most difficult to use.. I've read the comments on the Bitbucket blog regarding this, but nobody has bothered to change this.

      1. Ed,

        The lack of specifying a branch is indeed a limitation. However, we haven't had any reported issues with the Jenkins hook in some time. If you have had issues, we'd be happy to hear from you at support@bitbucket.org so that we can address them.

        EDIT: This comment is no longer accurate or current.

        1. Marcus, this hook works so much better than yours.. it's SO much easier to configure.

          - I need a single entry for each repo, and that entry is the same for all repos!! Yeah.

          - I then configure jenkins to have as many projects as I need.. Each project specifies which branch to pay attention to.. that's how it need to be.. 

          If we need to create a new hook AND a new Jenkins project for each instance, this is a lot of extra work, Further, each hook under bitbucket is unique, and we must get the URL Encoded project name, all of that is a major pain and duplication of effort.. 

          I honestly think Atlassian can do better.

        2. Marcus, this hook works so much better than yours.. it's SO much easier to configure.

          - I need a single entry for each repo, and that entry is the same for all repos!! Yeah.

          - I then configure jenkins to have as many projects as I need.. Each project specifies which branch to pay attention to.. that's how it need to be.. 

          If we need to create a new hook AND a new Jenkins project for each instance, this is a lot of extra work, Further, each hook under bitbucket is unique, and we must get the URL Encoded project name, all of that is a major pain and duplication of effort.. 

          I honestly think Atlassian can do better.

    3. Your Jenkins Hook URL now says:

      The page you were looking for may have been renamed to the following:

      Emphasis added; we have Bitbucket Server (alias Stash.)

      1. The Jenkins hook I was referring to was only ever available in Bitbucket Cloud, and has since been deprecated. For Bitbucket Server, follow the guidance given by the plugin maintainers. Sorry for the confusion.

        1. This plugin has a lot of issues, especially for usage with Bitbucket Server. Hence, for all the people who are not familiar with doing the fixes by themselves, it doesn't work. As the pull requests are not processed (some of the issues have already been fixed) the issues still remain.

          For me it seems like that this plugin is more or less dead...

    4. Since my comments were made in 2014, we have made numerous changes to Bitbucket Cloud, as well as our other products. This plugin has as well. The Bitbucket Cloud team recommends using this plugin (though Atlassian does not provide support for it), as we have deprecated our older service hooks system in favor of Webhooks. The instructions on this page were updated to reflect that some time ago

      My apologies for the lack of edits to my original comments as things have evolved around them over the years. My previous comments should be ignored, and I have edited them to reflect that.

  4. I've had pretty good success with this plugin, but it has not been perfect.

    I'll have some projects that just won't trigger. I've reviewed all of the settings multiple times.. but can't figure out why it won't trigger

    I'll do a push to origin/develop, and it triggers.. then a push to origin/release, no trigger..

    Any ideas/thoughts?

    1. Look at the SCM settings for that project, I believe this plugin will only trigger a build for changes to branches that match the pattern you have setup in the Git SCM setup for the project.

    2. I am having the same issue. I can trigger on master, but I can't trigger on feature/* or */feature/* etc. I have verified it's not my syntax for the branch specifier because the polling option works. Any insight here?

      1. Not sure what I did, but now it's working.

  5. I have created two jobs in Jenkins, one with build trigger as "Build when a change is pushed to BitBucket" and other with the trigger "Build periodically @midnight". So I was expecting when I push something on bitbucket 1st job will start and the 2nd one will start at midnight. But to my annoyance whenever I push something on bitbucket both jobs get started! What am I doing wrong?

  6. Any idea when this plugin change will be released https://github.com/jenkinsci/bitbucket-plugin/commit/a4bcb56410ddd0836b1a9b7170769368449465de  It would be nice to have this change so that my merge commits would trigger a build

  7. This plugin really interests me for the fact it looks like it will build only the branch that was commit.
    Unfortunately I haven't had any luck getting it to trigger any build (surprising as it's laid out so simply). Is this plugin currently active and functional with Jenkins 1.598?

  8. For people who are having trouble making this plugin work, do not forget the '/' at the end of the URL in the hook:

    http://<jenkins-url>/bitbucket-hook/

    I spent some time trying to figure out why the plugin was not working and I just had to put '/' at the end.

  9. Noticed bitbucket.org has just outdated the plain POST service and introduced the Webhook. I tried the new service but when jenkins received the hook, it gave me the following error message.

    It seems to be related to a json object parsing.

    Jenkins log message:
    Error while serving http://MY_JENKINS_URL/bitbucket-hook/
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:298)
    at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:161)
    at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:96)
    at org.kohsuke.stapler.MetaClass$2.dispatch(MetaClass.java:165)
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
    at org.kohsuke.stapler.MetaClass$13.dispatch(MetaClass.java:411)
    at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
    at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
    at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)
    at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:123)
    at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:114)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:48)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
    at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at jenkins.security.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:117)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:135)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:93)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
    at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:67)
    at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
    at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
    at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:81)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
    at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1474)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:499)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:370)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
    at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:960)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1021)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
    at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: net.sf.json.JSONException: JSONObject"user" not found.
    at net.sf.json.JSONObject.getString(JSONObject.java:2040)
    at com.cloudbees.jenkins.plugins.BitbucketHookReceiver.processPayload(BitbucketHookReceiver.java:104)
    at com.cloudbees.jenkins.plugins.BitbucketHookReceiver.doIndex(BitbucketHookReceiver.java:59)
    ... 71 more

  10. Are there any plans to support CSRF? I'd like to enable this in my Global Security settings, but when I do, it prevents this plugin from working. Thanks.

  11. I noticed that 1.1.3 is in the changelogs and there's a 1.1.3 release in the github repo, but the reported latest version still is 1.1.2

    Is there something that was missed releasing the plugin to be the latest from the repo?

  12. removing.  double post. see message below.

  13. I'm using v1.5 of the plugin and trying to integrate with Bitbucket.  The autogenerated webhook is failing due to the CSRF protection. I've tried updating the hook url to include username:apitoken but that still failed.

    Does anyone have a solution?

  14. Using the plugin version 1.1.5, two of my jobs is not acting on changes to the branch. Running "git -c core.askpass=true ls-remote -h git@<repo>" manually makes it obvious that the reference is different from the ref that was last built for that branch, but the plugin doesn't find the changes? Any ideas on how to reset this job or otherwise troubleshoot this? It works fine for other jobs.

    output:

    "aa7f51d78fa06b71ab7bff9ec6dafd58846bb7a2        refs/heads/qa"

    Started on Jun 22, 2016 11:44:28 AM

    Using strategy: Default

    [poll] Last Built Revision: Revision b95dfab3e52203da5d3f8551cbe5506db894141b (refs/remotes/origin/qa)

    using GIT_SSH to set credentials bitbucket readonly key

     > git --version # timeout=10

     > git -c core.askpass=true ls-remote -h git@bitbucket.org:<repo> # timeout=10

    Found 4 remote heads on git@bitbucket.org:<repo>

    Ignoring refs/heads/develop as it doesn't match any of the configured refspecs

    Ignoring refs/heads/master as it doesn't match any of the configured refspecs

    Done. Took 1.1 sec

    No changes

    Started on Jun 22, 2016 11:44:28 AM
    Using strategy: Default
    [poll] Last Built Revision: Revision b95dfab3e52203da5d3f8551cbe5506db894141b (refs/remotes/origin/qa)
    using GIT_SSH to set credentials bitbucket readonly key
     > git --version # timeout=10
     > git -c core.askpass=true ls-remote -h git@bitbucket.org:privacynow/ws-content-antiphishing.git # timeout=10
    Found 4 remote heads on git@bitbucket.org:privacynow/ws-content-antiphishing.git
    Ignoring refs/heads/develop as it doesn't match any of the configured refspecs
    Ignoring refs/heads/qals as it doesn't match any of the configured refspecs
    Ignoring refs/heads/master as it doesn't match any of the configured refspecs
    Done. Took 1.1 sec
    No changes

  15. I've been using GitLab CI plugin for Jenkins and it seems working very well also with Pull Request.

    Have you planning to implement Pull Request support for this plugin? Thanks you very much! 

  16. I have setup Bitbucket to talk to my Jenkins server and the Jenkins system logs say it gets it as well as starts a build but no build is ever created:Aug 29, 2016 12:23:59 PM INFO com.cloudbees.jenkins.plugins.BitbucketJobProbe triggerMatchingJobs
    Triggering BitBucket job Android Appium

    Any ideas of how to troubleshoot this?

    1. Figured it out. The logs in the job mention that it didn't run due to it not matching the branch that was specified.

    2. I had the same problem in a pipeline build. It worked after I used "**/master" instead of the default value "*/master" as the branch specifier. In a freestyle project the single asterisk seems to work fine.

  17. Is it an issue or change needed in the EnvInject or Bitbucket Plugin for my situation? I create a new variable called BUILD_BRANCH_LOCAL in the  "Prepare an environment for the run" section and use this variable as to set the refspecs and branch in the SCM  Git section. The BitBucket plugin seems to ignore this new variable and does not detect any changes.

  18. Are there any plans to support Pull Requests (or is there an easy work around)?

  19. The last releases 1.1.7 and 1.1.8 doesn't work when my Bitbucket server is something like https://myexampleserver.com/bitbucket. It removes the /scm from the URI and ended up finding no match between jobs to trigger the build

     
    my Jenkins logs:
    Trying to match https://myexampleserver.com/bitbucket/scm/project/repo <--> https://myexampleserver.com/bitbucket/project/repo
     
    https://github.com/jenkinsci/bitbucket-plugin/blob/ce068b7f2cbf5250aa6d54c3acdd455d45b56246/src/main/java/com/cloudbees/jenkins/plugins/BitbucketJobProbe.java#L93
     
    Is there any workaround for this? 

     

  20. There is issue, when I try use env.BITBUCKET_PAYLOAD in scripted pipeline:

    I have code in pipeline: 

    echo "payload: ${env.BITBUCKET_PAYLOAD}" 

    and result is: payload: null

    I discovered jenkins logs (for log level FINEST) and don't saw log "Injecting BITBUCKET_PAYLOAD: {0}" from class BitBucketPayload

    However other logs, such as "Processing new Webhooks payload", present and payload exist in webhook request

    Plugin version is 1.1.5, 1.1.8

    How can I use payload from webhook in pipelines?

    1. It looks like the BITBUCKET_PAYLOAD environment variable does not currently work in Pipeline jobs. There's a workaround on this Stackoverflow page that involves setting up a Freestyle job and having that trigger your Pipeline job.

  21. Hello,

    When we check the PULL request triggers and we create a pull request in Bitbucket server nothing happens on the jenkins side, we are expecting to get the jenkins triggered since in the plugin we have the pull request created checked.

    Can someone please advise ?

    Thank you

    1. You will have to use a different plugin for it.

      Bitbucket pullrequest builder plugin

       

    2. This is because of JENKINS-49177 - Getting issue details... STATUS

      This issue has already been fixed in January. Unfortunately nobody is merging the PR. I have checked out the code from github and fixed it by myself. Additionally I have fixed another issue with .git ending for repo URL. This doesn't work as well. There some more issues with SSH repo URL. But as long as nobody is motivated to merge a PR, I'm not motivated to provide a fix for all...