3

I have several Jenkins pipelines, all importing a shared library from Bitbucket for some utility methods, and I want to send build status notifications to each project's own Bitbucket repo.

I installed the Bitbucket build status notifier plugin, but I'm experiencing a weird behavior: when bitbucketStatusNotify is being called in my pipeline, this happens:

Sending build status INPROGRESS for commit <sha> to BitBucket is done!

And that would be ok, but <sha> is the commit id of the last commit on the shared library, not on the actual project being built, so build status notifications are actually being sent to the shared library repo instead of the proper one.

I thought this was an issue with the library being set as "load implicitly" in the Jenkins configuration, so I tried loading it explicitly with @Library in my jenkinsfile, but the same behavior occurs.

Since the build status notifier plugin has no way to specify the commit id to send notifications to, is there something I'm missing to have it send notifications to the proper commit id?

030
  • 10,842
  • 12
  • 78
  • 123
Raibaz
  • 9,280
  • 10
  • 44
  • 65
  • Different plugin, but sounds similar to [JENKINS-41996](https://issues.jenkins-ci.org/browse/JENKINS-41996) – mkobit Jan 03 '18 at 18:13
  • 2
    I ended up submitting this https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin/pull/37 to try and fix it :) – Raibaz Jan 04 '18 at 08:33
  • https://devops.stackexchange.com/a/6594/210 – 030 Mar 13 '19 at 11:37

1 Answers1

-1

Here is an example of Bitbucket Cloud:

First install HTTP Request plugin on Jenkins

Then use the following Pipeline Code:

void notifyBitbucket(state)
{
    def object_data = "{\"state\": \"${state}\",\"key\": \"${env.JOB_NAME} ${currentBuild.displayName}\",\"name\": \"${env.JOB_NAME} ${currentBuild.displayName}\",\"url\": \"https://jenkins/job/${env.JOB_NAME}/${currentBuild.number}/\",\"description\": \"\"}"
    def response = httpRequest authentication: '<credential ID>', acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: object_data, url: "https://api.bitbucket.org/2.0/repositories/<user name>/<repo>/commit/<commit id>/statuses/build"
}
Bentaye
  • 9,403
  • 5
  • 32
  • 45
Joey
  • 1
  • 3