Search code examples
gitjenkinsbitbucketjenkins-pluginscloudbees

Setup Bitbucket repository for Jenkins (for Cloudbees)


This document is not very helpful:

https://developer.cloudbees.com/bin/view/DEV/Bitbucket

I have:

  1. Added CloudBees DEV@cloud public key to the Bitbucket
  2. Added the hook
  3. Have installed the Jenkins Bitbucket plugin (from within Cloudbees)

But how to actually use a (Private) Bitbucket repo for a Jenkins Build.


Solution

  • AFAIK, at the end you are using a Git repository, so it is the same if your repo is in one provider or another one. So your git repo should have a Repository URL like this one below (https or ssh) and a username/password.

    https://[email protected]/felix/my-git-repo.git
    

    So you need to enter these information on your Jenkins job->Source Code Management->Git Repositories (same thing for Forge (CloudBees), GitHub, ....)

    The BitBucket plugin just let you configure Bitbucket to automatically trigger a build on commit. The method below is a workaround as the way explained on the doc doesn't work.

    On Jenkins:

    1. Get your API token from your Jenkins instance. You can get it form here:

      https://[account].ci.cloudbees.com/user/[the-user-portion-of-your-email]/configure

    2. On your Jenkins job, you need to enable:

      • Trigger builds remotely (e.g, from scripts). Need to add the authentication token.

      • Build when a change is pushed to BitBucket

    On BitBucket

    1. Instead of adding a POST hook, add a Jenkins Hook.
      • Endpoint

    https://[the-user-portion-of-your-email]:[apitoken]@[account].ci.cloudbees.com

    NOTE: the-user-portion-of-your-email should correspond with one of the user at "People" section in Jenkins.

    • Add project name = job name in Jenkins

    • Add token

    UPDATE

    POST is working perfectly, CloudBees just missed the character"/" at the end of the URL used to hook the trigger. So it should be https://[account].ci.cloudbees.com/bitbucket-hook/ and NOT https://[account].ci.cloudbees.com/bitbucket-hook

    Official CloudBees BitBucket doc are now updated.