Jenkins将通知发送到错误的提交ID [英] Jenkins sending notifications to the wrong commit id

查看:147
本文介绍了Jenkins将通知发送到错误的提交ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个Jenkins管道,所有管道都从Bitbucket导入了一些实用程序的共享库,并且我想向每个项目自己的Bitbucket存储库发送构建状态通知.

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.

我安装了 Bitbucket构建状态通知程序插件,但是我遇到奇怪的行为:在我的管道中调用bitbucketStatusNotify时,会发生这种情况:

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!

那没关系,但是<sha>是共享库上的最后一次提交的提交ID,而不是正在构建的实际项目上的提交ID,因此,构建状态通知实际上是发送到共享库回购而不是合适的人.

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.

我认为这是在Jenkins配置中将库设置为隐式加载"的问题,因此我尝试在我的jenkinsfile中使用@Library显式加载它,但是会发生相同的行为.

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.

由于构建状态通知程序插件无法指定向其发送通知的提交ID,因此我是否缺少使它向正确的提交ID发送通知的东西?

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?

推荐答案

以下是Bitbucket Cloud的示例:

Here is an example of Bitbucket Cloud:

首先在Jenkins上安装HTTP请求插件

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

这篇关于Jenkins将通知发送到错误的提交ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆