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.
The documentation available very nicely explains how to create credentials and add them to Jenkins (I added them globally to 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)
I have tried using it in Jenkins file like this:
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.