简体   繁体   English

bitbucket-build-status-notifier-plugin 使用凭据和管道

[英]bitbucket-build-status-notifier-plugin using credentials with pipeline

I have been trying to get Jenkins' "Bitbucket Build Status Notifier" plugin to notify Bitbucket whether the Maven build after a commit was successful or not.我一直在尝试使用 Jenkins 的“Bitbucket Build Status Notifier”插件来通知 Bitbucket 提交后 Maven 构建是否成功。

The documentation available very nicely explains how to create credentials and add them to Jenkins (I added them globally to Jenkins master)可用的文档很好地解释了如何创建凭据并将它们添加到 Jenkins(我将它们全局添加到 Jenkins master)

Unfortunately neither the plugin page ( https://wiki.jenkins-ci.org/display/JENKINS/Bitbucket+Cloud+Build+Status+Notifier+Plugin ), nor the GitHub project ( https://github.com/jenkinsci/bitbucket-build-status-notifier-plugin ) does not describe how to use Bitbucket credentials with pipeline version of notifier ( https://issues.jenkins-ci.org/browse/JENKINS-33841 )不幸的是,插件页面( 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 )

I have tried using it in Jenkins file like this:我曾尝试在 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')
                }
            }
        }
    }
}

Unfortunately I always seem to end up with不幸的是,我似乎总是以

[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

Those credentials definitely exist, but I am not sure how to tell the pipeline script how to use them.这些凭据肯定存在,但我不确定如何告诉管道脚本如何使用它们。

After reading more about Jenkins pipeline syntax and reviewing Snippet generator syntax tips (available on your Jenkins host via http://…/pipeline-syntax/) I understood the mistake was not to use withCredentials step, but to use the "credentialsId" option available for this plugin.在阅读了有关 Jenkins 管道语法的更多信息并查看了代码段生成器语法提示(可通过 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-....')

                }
            }
        }
    }
}

It might help someone you can get credentials from the URL in Jenkins when viewing the credential of interest using the control panel.当您使用控制面板查看感兴趣的凭据时,它可能会帮助您从 Jenkins 中的 URL 获取凭据。

It seems a bit strange you need to pass the credential id every time, maybe somebody can post how to define default ones?每次都需要传递凭证 ID 似乎有点奇怪,也许有人可以发布如何定义默认值?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jenkins 中带有 bitbucket 构建状态通知程序插件的多分支管道 - Multi branch pipeline with bitbucket build status notifier plugin in jenkins Jenkins Bitbucket 构建状态通知程序插件未显示 - Jenkins Bitbucket Build Status Notifier Plugin not showing jenkins 的 bitbucket-build-status-notifier 插件报告错误状态 - bitbucket-build-status-notifier plugin for jenkins reports wrong status Jenkins 2.3.5 构建通知(Emailext、bitbucket 构建状态通知程序)不工作 - Jenkins 2.3.5 Build Notification (Emailext, bitbucket build status notifier) Not Working 如何使用Bitbucket,Jenkins和ElasticBeanstalk构建部署管道 - How to build a deployment Pipeline Using Bitbucket, Jenkins and ElasticBeanstalk 使用凭据插件运行Jenkins管道步骤的问题 - Issue running Jenkins Pipeline Steps using Credentials plugin 尽管凭据正确,但Jenkins仍会存储隐匿通知程序插件错误 - Jenkins to Stash Notifier Plugin error despite correct credentials 如何使用 BitBucket API 获取 PR 的构建状态? - How to get build status of PR using BitBucket API? 如何检查构建状态,从 BitBucket 管道运行 Jenkins 作业? - How do I check for build status, running Jenkins jobs from a BitBucket pipeline? 在Jenkins 2.0 multibranch管道上使用stash notifier插件 - Use stash notifier plugin on Jenkins 2.0 multibranch pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM