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?
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"
}
来源:https://stackoverflow.com/questions/48075292/jenkins-sending-notifications-to-the-wrong-commit-id