我一直试图让詹金斯' " 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)都没有描述如何使用管道版通知程序(https://issues.jenkins-ci.org/browse/JENKINS-33841)的Bitbucket凭证
我已尝试在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
这些凭证肯定存在,但我不知道如何告诉管道脚本如何使用它们。
答案 0 :(得分:2)
在阅读了更多有关Jenkins管道语法和查看Snippet生成器语法提示(通过http:// ... / pipeline-syntax /在Jenkins主机上提供)之后,我明白错误不是使用withCredentials步骤,而是使用“ credentialsId“此插件可用的选项。
pipeline {
agent {
label 'jenkins-slave'
}
stages {
stage ('Build') {
steps {
script {
bitbucketStatusNotify(buildState: 'INPROGRESS', credentialsId: '050a0876-fb6b-....')
sh '''#!/bin/bash
mvn clean package
...
'''
bitbucketStatusNotify(buildState: 'SUCCESSFUL', credentialsId: '050a0876-fb6b-....')
}
}
}
}
}
使用控制面板查看感兴趣的凭据时,可以帮助您从Jenkins的URL获取凭据。
您每次都需要传递凭证ID似乎有点奇怪,也许有人可以发布如何定义默认ID?