Jenkins service management

With this service, you can integrate Bitbucket with Jenkins, an extendable open source continuous integration server. If you are having trouble with the service, see Troubleshoot Bitbucket services. For help understanding Jenkins' security options and their implications to triggering remote builds, please review the Jenkins documentation

Setting Up the service

 You must have administrative access on a repository to add this service.

  1. Go to the repository's settings.
  2. Click Services in the left-hand navigation.
    The Services page appears.
  3. Select the Jenkins service from the services dropdown.
  4. Click Add service.
    A new section appears for the Jenkins service.
  5. Enter the following information:

    Field Explanation Example Required
    Csrf Enabled If set, the service will work with Jenkins when csrf is enabled on the server.   (error)
    Module name If set, only commits to the specified module (or directory) will trigger a Jenkins build. apps/Bitbucket (error)
    Token If you have token authentication enabled for your builds, insert it here.   (error)
    Project Name The name of the Jenkins job you wish to run builds on bitbucket Selenium Tests (tick)
    Endpoint

    The endpoint URL for your Jenkins instance. This can be any standard URL in the format. Basic authentication will be used when providing a username and password in the field.

    https://www.bitbucket.org:8080/jenkins/

    (tick)
  6. Press Save.

Was this helpful?

Thanks for your feedback!

62 Archived comments

  1. User avatar

    Dan Garthwaite

    I am also having trouble with this feature.  There is precious little out there out google to help and it seems it may be due to a change in jenkins API.

    Could the generated URL be presented under the form in the UI?  That would be tremendous help tracking this bug down.

    27 Jan 2012
  2. User avatar

    Anonymous

    Dumb question: is the "Endpoint" supposed to be a publicly accessible url for your Jenkins server?  It seems so. Do people really expose their Jenkins build servers and all their source code to the public?  If it's not public, then I have no idea what is supposed to go in that field.

    Any Bitbucket guys viewing these forums?

    27 Apr 2012
    1. User avatar

      Brian Nguyen

      Yes, in order to use the Jenkins service, you will need to make your server publicly available. You can configure Jenkins to require Bitbucket access your server via basic auth. Then you can set the endpoint to:

      <username>:<api token>@<jenkins server host>
      27 Apr 2012
  3. User avatar

    Anonymous

    Hi, it would be really great to be able to test this feature without performing a commit. Github has a "test" button and it certainly makes things easier when trying to figure out why it isn't working.

    Also is it possible to document how bitbucket interacts with Jenkins based on the parameters so that it can be seted with curl? For some reason our commits stopped being triggered in our Jenkins instance a few weeks ago and I have no idea why it isn't working.

    13 May 2012
  4. User avatar

    Anonymous

    Endpoint: https://user:api-token@mydomain.com/jenkins/

    Projektname: MyProjekt

    Token: mytoken

    The token is set in the project configuration, the api token is taken from the user configuration.

    25 Jun 2012
    1. User avatar

      Anonymous

      This is the most clear example and, in my opinion, should be appended to the documentation.

       

      Thanks.

      13 Jun 2013
      1. User avatar

        Jake Bishop

        agreed

        17 Sep 2013
  5. User avatar

    Stan Gogh

    Is there a way to only trigger a build when a commit is done in a specified branch?

    03 Jul 2012
    1. User avatar

      Anonymous

      I'm looking for the same thing.  I don't want a build pushed out for every time something is committed to a feature branch.  Only my main branch should cause a new build.

      27 Jul 2012
      1. User avatar

        Anonymous

        I found a solution.  It is documented here: http://stackoverflow.com/questions/5784329/how-can-i-make-jenkins-ci-with-git-trigger-on-pushes-to-master

        In a nutshell, you have to use the bitbucket POST HOOK, not a JENKINS HOOK, and you post to:

        http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>

         

        Also, you have to have your modify your Jenkins job to use SCM polling, but leave the schedule part blank.  

        That is critical.  You must check the SCM polling, but leave the cron entry blank.

        05 Nov 2013
    1. User avatar

      Anonymous

      If we could specify that the URL should go to <jenkins url>/polling instead of <jenkins url>/build then Jenkins can check if there's new changes to that branch and build if there are.

      27 Jul 2012
      1. User avatar

        Anonymous

        I've built an application that lets you easily do this.  It's a lightweight node app that receives post-receive hooks from bitbucket, and forwards it to jenkins based on the branch that was committed to.

        Check it out here (I need to improve the documentation):

        https://github.com/oveddan/gitBuildForwarder

        27 Jul 2012
        1. User avatar

          Anonymous

          We have the same kind of setup running through PHP: https://github.com/wieni/jenbucket

          27 Mar 2013
          1. User avatar

            Anonymous

            WOW GREAT FIXZ!!!  (Thanks for the workaround.)

            02 Oct 2013
  6. User avatar

    Anonymous

    I entered Project name and Endpoint in public Jenkins. When i commit the changed, should it start automaticly build? it didnt start .

     

    13 Aug 2012
    1. User avatar

      manthony

      Please send an email to support@bitbucket.org to get assistance with this.

      13 Aug 2012
    1. User avatar

      Anonymous

      I had a similar issue, it ended up being a firewall issue, that the port wasn't open on the server. Unfortunately, bitbucket does not let you know if it successfully hit the url or not - it would be great if a log was visible for these posts, or even the server response was visible.

      13 Aug 2012
    1. User avatar

      Stan Gogh

      I had a similar issue, it ended up being a firewall issue, that the port wasn't open on the server. Unfortunately, bitbucket does not let you know if it successfully hit the url or not - it would be great if a log was visible for these posts, or even the server response was visible.

       

      13 Aug 2012
  7. User avatar

    Barry S

    Hi,

    I have tried to get the Bitbucket Jenkins service integration working by following the steps outlined above.

    My Jenkins server has security enabled and hence I have used a token for my job as outlined @ https://wiki.jenkins-ci.org/display/JENKINS/Quick+and+Simple+Security.

    However, this doesn't trigger my remote job. When I try to hit the url from the command line using curl : i.e curl http://<user>:<pass>@<server_name>/jenkins/job/<project_name>/build?token=<my_token> then the remote job gets triggered.

    Additionally I also try to do a Bitbucket POST using the URL outlined in curl but even this doesn't trigger the job.

    Help appreciated on this.

    ~Barry

    15 Aug 2012
    1. User avatar

      manthony

      Hi Barry,

      Please send an email to support@bitbucket.org our support team is very responsive.

      Cheers,

      Mary

      15 Aug 2012
  8. User avatar

    Anonymous

    I gave up trying to support the service because it gives little feedback when things are going wrong. It also doesn't support a secured jenkins nor triggering a branch. Finally it requires more setup on jenkins site (authentication URL).

    A better solution (at least for git users) is to use Jenkins support of push https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-Pushnotificationfromrepository 

    It requires no more specific authentication, no per job specific configuration on the bitbucket side, and works with branches out of the box as it reuses the polling mechanism.

    Jerome@WeWantToKnow

    21 Sep 2012
  9. User avatar

    Anonymous

    What worked nicely for me is to leave module name and token empty, and just fill out project name and endpoint with excatly the url format Barry S posted above. Obviously you need to add the appropriate user with password in Jenkins first.

    Thanky Barry (wink)

    Cheers

    Phil

    24 Oct 2012
  10. User avatar

    Anonymous

    Same here.

    Tried every suggestion here but it just wouldn't work! I verified with curl that my endpoint is correct.

    Lefteris

    01 Nov 2012
  11. User avatar

    Kief Morris

    Here's what worked for me:

    Module name: Blank

    Token: The token from the build job I want to run

    Project name: The build project name

    Endpoint: http://username:usertoken@jenkins.mydomain.com

    Key points: 

    • The usertoken in the URL is the token for the user account, not the password, and not the same token used for the job.
    • The endpoint URL is not the full URL. Bitbucket adds on the /build/jobname?token=token, using the other fields you enter.

     

    05 Nov 2012
  12. User avatar

    Anonymous

    Does this support the buildWithParameters option of Jenkins? My projects on jenkins won't trigger with just using the "build" parameter.

    20 Nov 2012
    1. User avatar

      Anonymous

      I documented how to trigger Jenkins Parameterized Jobs here.

      Basically you leave the Project Name field blank and use the following endpoint URL:

      http://username:apitoken@your.jenkins.url/job/your.job.name/buildWithParameters 

       

      06 Mar 2014
  13. User avatar

    Alex Soto

    Another success here for me.  It took some troubleshooting as there is no feedback from the bitbucket callback that I could find.

    My Jenkins is integrated with Google Apps for logins.  Therefore, your user name has an @ sign in it.  So you need to make sure you urlencode it.

    For example, user@example.com is 'user%40example.com'.

     

    My example url:

    https://user%40example.com:APITOKEN@example.com/hudson

    29 Nov 2012
  14. User avatar

    Anonymous

    This is truly worthless if I cant build per branch, sigh.... 

    31 Dec 2012
  15. User avatar

    Anonymous

    After few hours I finally found out that in our case option "" must be turned off.

    Hope this might help someone...

    06 Jan 2013
  16. User avatar

    Rob Moore

    Logging would really help here. I don't see anything happening on the Jenkins server side (not even an attempt to call the server). I suspect it's because our server requires SSL and there's some issue with the certificate (perhaps the CA isn't supported).

    14 Jan 2013
  17. User avatar

    Jeroen Thora

    is it possible to let bitbucket trigger a jenkins job if an branch get a commit? Is that the use for the module field?

    15 Jan 2013
    1. User avatar

      Christian Jensen

      Module name is very VERY confusing!

      Is this relating to a particular branch?

       

      I want one branch to trigger one jenkins job (dev) and other branch to trigger a different job (staging)

       

      Any idea how to do this?

      30 Jan 2015
  18. User avatar

    Anonymous

    Hmm it actually not work with my jenkins instance hostet by cloudbees ... I set a auth token in jenkins and set all necessary attributes in bitbucket but after a push to my repo nothing happens ... has anyone experience with jekins on cloudbees and bitbucket ?

    16 Jan 2013
    1. User avatar

      Anonymous

      I am using Jenkins hosted by Cloudbees and I just set this up without any problems (besides the fact that builds will be triggered if someone commits to branch, which makes this hook pretty much useless).

      You have to watch out for 2 things:

      • Anonymous user needs Read access OR use the Build Token Root Plugin
      • You need to add a trailing ampersand to the ENDPOINT and leaving everything else blank!
      05 Nov 2013
  19. User avatar

    Nicolas De Loof

    The service endpoint doesn't seem to support crendetials. I tried to pass them in URL as http://user:secret@jenkins.server.com but don't get it to send me commit notification.

    23 Jan 2013
    1. User avatar

      Alex Soto

      May need to url encode things.  See my previous post on what I had to do.

       

      Re: Jenkins Service Management

      23 Jan 2013
  20. User avatar

    Nicolas De Loof

    I did, but didn't got it.

    Could you fill a RFE to enter credentials as a dedicated input, and also to provide a test button ?

    23 Jan 2013
  21. User avatar

    cdelgado

    Is it possible to fire a build without commiting?

    I'm setting this up and it would help for testing purposes.

    Thanks

     Carlos

    13 Feb 2013
  22. User avatar

    Anonymous

    Mary,

      I find it really insane / lame that an employee of Atlassian is suggesting we tweet our issue to get attention..  Can you simply bring this crap up to the devs? 

    -John

    26 Mar 2013
    1. User avatar

      manthony

      This problem was fixed except in configurations where CSRF is enabled. If that is the case for you, please follow https://bitbucket.org/site/master/issue/6503/jenkins-service-broker-should-support for a resolution.  If that isn't the case for you, see Troubleshooting Bitbucket Services for information on debugging.  If you still have problems, please raise an issue with support@bitbucket.org.

      I do mention problems like this directly to dev. Also, they do regularly triage issues. Even so, as you can imagine, often some issues have priority above other issues. I suggested tweets because the devs seem to follow them closely. I guess a tweet is the equivalent of a personal commercial in a long day of coding.  

      26 Mar 2013
  23. User avatar

    Jonathan Sanchez

    Hi

    someone knows any way to will trigger only if a tag was created?

    Thanks

    23 May 2013
  24. User avatar

    Johan Sjöberg

    I found another solution, with a secured Jenkins using the plugin https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin

    Entering only the following URL as Endpoint allows anonymous (token-based) trigger of jobs

    https://myjenkins.com/buildByToken/build?job=myJob&token=myToken&

    The trailing ampersand is used to "ignore" the parameters bitbucket appends, /build/jobname?token=token

     

    I believe this option should be supported natively (that of only entering the jenkins build-url). 

    26 Jun 2013
    1. User avatar

      Anonymous

      You sir, need an award.  I've tried so many variations that I almost gave up, until I read your comment.  The trailing ampersand was the trick (and leaving everything as blank).  Thank you.  I wish I read your comment earlier.

      05 Nov 2013
    1. User avatar

      Anonymous

      This worked for me as well, perfect!

      16 Feb 2014
    1. User avatar

      Trygve Hardersen

      This actually works... You're great!

      04 Aug 2015
  25. User avatar

    Anonymous

    Does this work for Jenkins not running on port 80? As I am sure my config is correct and its still not working.

    20 Sep 2013
    1. User avatar

      manthony

      Please file a support ticket for this.  

      20 Sep 2013
  26. User avatar

    cdelgado

    What's the difference between a link and a hook?

    04 Oct 2013
    1. User avatar

      manthony

      A hook is a  place in a software program that allows an external person or program to react to or tap into a program. The hook in this case is more like an event hook which allows Jenkins to respond to a POST event from Bitbucket.

      04 Oct 2013
  27. User avatar

    Anonymous

    I previously had a working jenkins hook but for some reason it stopped working. But I got the POST hook to work instead:

     https://<username_in_jenkins>:<user_auth_token_in_jenkins>@<jenkins_server>/jenkins/job/<jenkins_project_name>/build?token=<project_auth_token>

    19 Nov 2013
  28. User avatar

    Jason Patel

    Is there a way to setup hooks to push to amazon's SQS or SNS services like there is for github?

    05 Mar 2014
  29. User avatar

    Anonymous

    I created https://wiki.jenkins-ci.org/display/JENKINS/Bitbucket+Plugin, that make it simpler to setup bitbucket/jenkins integration

    24 Mar 2014
    1. User avatar

      johntdyer

      I looked at this today and I can not get it working.  There is no logging and the instructions are not very clear.  Looks like this could be the solution we have been looking for, but at the very least the docs need some flushing out. 

      04 Apr 2014
  30. User avatar

    marko.lisica

    Anyone using pull request hook?

    How come simple hook is written so bad?

    https://bitbucket.org/site/master/issue/9641/pull-request-post-hook-bb-10740

    06 Jun 2014
    1. User avatar

      Marcus Bertrand [Atlassian]

      Does your open issue with us, and above also relate to the Jenkins hook? We're looking into the issue. If there is an additional issue specific to the Jenkins hook, please note it here.

      06 Jun 2014
      1. User avatar

        marko.lisica

        It has relation only to pull request hook.

        Simply explained, I dont want hook to be triggered if I post a comment on pul request.

        I know there is checkbox, and I unckeck it, but still when I comment on a pullrequest hook is triggered and our Jenkins builds it again, posts build result as a comment and you get a loop.

        13 Jun 2014
        1. User avatar

          Marcus Bertrand [Atlassian]

          Can we move this conversation back into support and/or to the correct page at Pull Request POST hook management? We have an ongoing support ticket with you where we are still working to validate and test this issue.

          13 Jun 2014
  31. User avatar

    Chris Clark

    I spent hours trying to get this to work with a completely standard setup to no avail.  I could successfully trigger a Jenkins build from a browser/rest client (e.g. Postman) by sending a GET to http://<jenkins server url>:8080/job/<project name>/build?token=<token name> (which is the URL Jenkins says to use).  But this hook apparently can't do that.

    Finally settled with letting Jenkins poll BitBucket.

    13 Jun 2014
    1. User avatar

      Alex Soto

      It's been working for us.  It took a bit of troubleshooting.  I used a proxy like Runscope provides for free so you can see what's being sent.

       

      It's likely something simple, but the lack of visibility is what makes it hard to troubleshoot.  In our case the fact that we use google apps for auth on jenkins, so the user name is a full email (user@example.com) so we needed to url escape things properly.

       

      Good luck

      13 Jun 2014
  32. User avatar

    Brendan Mannix

    If you want to build conditionally, based on commits to a specific branch avoid using this hook

    Instead, setup a "POST" hook to: http://your_server.com:8080/git/notifyCommit?url=git@bitbucket.org:<your_account>/<your_repo>.git

    On your Jenkins job, just set a trigger to "Poll SCM" but with no schedule.  When commits occur to the repo, this hook will fire every time, and Jenkins will check to see if there are new commits (in the branch you designate) to build.  You can manage what jobs build based on commits to certain branches or directory paths in Jenkins itself.

    16 Jun 2014
    1. User avatar

      Tony Legrone

      You have saved me a lot of pain. Thank you!

      18 Mar 2015
  33. User avatar

    Jason Perry

    Is there a way to only fire this webhook if master changes? I make changes to a remote branch and it triggers a build with no changes.  This seems like a feature that should be supported, I know github does.  Please advise.

    Thanks,

    Jay

    22 Dec 2014
Powered by Confluence and Scroll Viewport