简体   繁体   English

Jenkins 向错误的提交 ID 发送通知

[英]Jenkins sending notifications to the wrong commit id

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.我有几个 Jenkins 管道,它们都从 Bitbucket 导入共享库以用于某些实用方法,并且我想将构建状态通知发送到每个项目自己的 Bitbucket 存储库。

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:我安装了Bitbucket 构建状态通知程序插件,但我遇到了一个奇怪的行为:当我的管道中调用bitbucketStatusNotify时,会发生这种情况:

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.这没问题,但是<sha>是共享库上最后一次提交的提交 ID,而不是正在构建的实际项目上,因此构建状态通知实际上是发送到共享库存储库而不是正确的。

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.我认为这是在 Jenkins 配置中将库设置为“隐式加载”的问题,所以我尝试在我的 jenkinsfile 中使用@Library显式加载它,但发生了相同的行为。

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?由于构建状态通知程序插件无法指定要向其发送通知的提交 id,是否缺少将通知发送到正确的提交 id 的内容?

Here is an example of Bitbucket Cloud:以下是 Bitbucket Cloud 的示例:

First install HTTP Request plugin on Jenkins首先在 Jenkins 上安装 HTTP Request 插件

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM