Jenkins sending notifications to the wrong commit id

此生再无相见时 提交于 2019-12-23 04:19:05

问题


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?


回答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"
}


来源:https://stackoverflow.com/questions/48075292/jenkins-sending-notifications-to-the-wrong-commit-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!