我有几个Jenkins管道,都是从Bitbucket导入一个共享库的一些实用程序方法,我想向每个项目自己的Bitbucket仓库发送构建状态通知。
我安装了Bitbucket build status notifier插件,但我遇到了一个奇怪的行为:当我的管道中调用bitbucketStatusNotify
时,会发生这种情况:
Sending build status INPROGRESS for commit <sha> to BitBucket is done!
这没关系,但<sha>
是共享库上最后一次提交的提交ID,而不是正在构建的实际项目,因此构建状态通知实际上是发送到共享库repo而不是适当的。
我认为这是一个问题,在Jenkins配置中将库设置为“隐式加载”,所以我尝试在我的jenkinsfile中使用@Library
显式加载它,但是会出现相同的行为。
由于构建状态通知程序插件无法指定要向其发送通知的提交ID,我是否缺少将通知发送到正确的提交ID?
答案 0 :(得分:-1)
以下是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"
}