我一直在尝试让 Jenkins 的“Bitbucket Build Status Notifier”插件通知 Bitbucket 提交后的 Maven 构建是否成功。
可用的文档很好地解释了如何创建凭据并将它们添加到 Jenkins(我将它们全局添加到 Jenkins master)
不幸的是,插件页面(https://wiki.jenkins-ci.org/display/JENKINS/Bitbucket+Cloud+Build+Status+Notifier+Plugin)和 GitHub 项目(https://github.com/jenkinsci/ bitbucket-build-status-notifier-plugin)没有描述如何将 Bitbucket 凭证与通知程序的管道版本一起使用(https://issues.jenkins-ci.org/browse/JENKINS-33841)
我曾尝试在 Jenkins 文件中使用它,如下所示:
pipeline {
agent {
label 'jenkins-slave'
}
stages {
stage ('Build') {
steps {
script {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '050a0876-fb6b-....',
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
bitbucketStatusNotify(buildState: 'INPROGRESS')
sh '''#!/bin/bash
mvn clean package
...
'''
bitbucketStatusNotify(buildState: 'SUCCESSFUL')
}
}
}
}
}
不幸的是,我似乎总是以
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.Exception: Credentials could not be found!
at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.sendBuildStatusNotification(BitbucketBuildStatusHelper.java:262)
at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.notifyBuildStatus(BitbucketBuildStatusHelper.java:252)
at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:189)
at org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifierStep$Execution.run(BitbucketBuildStatusNotifierStep.java:140)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate(ACL.java:221)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
这些凭据肯定存在,但我不确定如何告诉管道脚本如何使用它们。