0

I am trying to integrate Bitbucket cloud with Jenkins. I have Bitbucket plugin installed in Jenkins. I have configured the webhook in bitbucket cloud for the repository with url http://<jenkins_url>/bitbucket-hook/

I set up Jenkins job (I tried both pipeline and multibranch pipeline). In the Pipeline I have selected "Build when a change is pushed to BitBucket" and In the pipeline I have stages to fetch from bitbucket and build. I have specified to get from branch develop.

case 1: After I set this up I pushed some code to my repository(branch develop). I expected the pipeline to be triggered(since I have a webhook setup) nothing happens.
I triggered the build manually. It builds the project. Now if I push something to the repository, the build is getting triggered. Question here is Why didn't it triggered the first time and works only after a manual build.

case 2: I setup another pipeline. Exactly as the one before. But with branch as master. I tried to follow the same step(triggered manually first). Now when i pushed something to master. Nothing happens(even after manual build).

When I analysed the jenkins log. I see that there is a notification from bitbucket cloud as soon as something is pushed. But the json which is sent doesn't has branch information. May be that is the reason Jenkins is not able to decide which pipeline to trigger when there are multiple pipelines talking to same repository. Is my assumption correct? Is it a bug in Bitbucket cloud

The json recieved from bitbucket cloud looks like this

{
   "scm": "git",
   "website": null,
   "name": "myproject-api",
   "links": {
      "self": {
         "href": "https://api.bitbucket.org/2.0/repositories/my-team/myproject-api"
      },
      "html": {
         "href": "https://bitbucket.org/my-team/myproject-api"
      },
      "avatar": {
         "href": "https://bytebucket.org/ravatar/%7Bb07e7384-c622-44b1-8c5f-96104d36cfae%7D?ts=java"
      }
   },
   "project": {
      "key": "PB",
      "type": "project",
      "uuid": "{d9c0caa2-7d43-4a0e-8459-2c7c8c2bd287}",
      "links": {
         "self": {
            "href": "https://api.bitbucket.org/2.0/teams/my-team/projects/PB"
         },
         "html": {
            "href": "https://bitbucket.org/account/user/my-team/projects/PB"
         },
         "avatar": {
            "href": "https://bitbucket.org/account/user/my-team/projects/PB/avatar/32"
         }
      },
      "name": "MyProject Backend"
   },
   "full_name": "my-team/myproject-api",
   "owner": {
      "username": "my-team",
      "display_name": "my-team",
      "type": "team",
      "uuid": "{848f7612-ffbc-4dfb-8f67-ade4b604761c}",
      "links": {
         "self": {
            "href": "https://api.bitbucket.org/2.0/teams/%7B848f7612-ffbc-4dfb-8f67-ade4b604761c%7D"
         },
         "html": {
            "href": "https://bitbucket.org/%7B848f7612-ffbc-4dfb-8f67-ade4b604761c%7D/"
         },
         "avatar": {
            "href": "https://bitbucket.org/account/my-team/avatar/"
         }
      }
   },
   "type": "repository",
   "is_private": true,
   "uuid": "{b07e7384-c622-44b1-8c5f-96104d36cfae}"
}

Does anyone have any idea how to successfully get webhooks working with bitbucket cloud and Jenkins. Most of the questions on SO regarding this talks about Bitbucket server and not Bitbucket cloud.

pvpkiran
  • 25,582
  • 8
  • 87
  • 134

1 Answers1

1

I had similar issues solved by doing following steps:

  1. Uninstall old 'Bitbucket' plugin
  2. Removed webhook at bitbucket that was set as:
    • http://<Jenkins URL>/bitbucket-hook/
  3. Install 'Bitbucket Branch Source Plugin'
  4. Set new webhook at bitbucket repository as:
    • http://<Jenkins URL>/bitbucket-scmsource-hook/notify/

Cheers!!!

rraj gautam
  • 125
  • 1
  • 1
  • 10
  • This is the solution that works for Multibranch pipeline.But I found another issue while creating my multibranch pipeline job using **blue ocean** . By looking to jenkins multibranch log file, `/var/lib/jenkins/logs/jenkins.branch.MultiBranchProject.log`. I figured out the issue was due to **owner name** at bitbucket source on project configure. **blue ocean** encodes the owner name, that was why it showed **0 matched** on log. changing the owner name solved my issue. – rraj gautam Oct 01 '20 at 07:55