首页 文章

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

提问于
浏览
1

我有几个Jenkins管道,都是从Bitbucket导入一些共享库的一些实用程序方法,我想向每个项目自己的Bitbucket仓库发送构建状态通知 .

我安装了Bitbucket build status notifier插件,但我遇到了一个奇怪的行为:当我的管道中调用 bitbucketStatusNotify 时,会发生这种情况:

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

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

我认为这是一个问题,在Jenkins配置中将库设置为"load implicitly",所以我尝试在我的jenkinsfile中使用 @Library 显式加载它,但是会出现相同的行为 .

由于构建状态通知程序插件无法指定要向其发送通知的提交ID,我是否缺少将其发送到正确的提交ID的通知?

1 回答

  • 0

    以下是Bitbucket Cloud的一个示例:

    首先在Jenkins上安装HTTP Request插件

    然后使用以下管道代码:

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

相关问题