I have configured webhooks in Bitbucket to capture PR "create"/"update" events and perform builds on Jenkins to provide build statuses in Bitbucket.
After running the build successfully in Jenkins(I get a blue bubble) it notifies Bitbucket about the build status and receives a successful response.
Mar 15, 2018 3:55:07 AM org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper sendBuildStatusNotification
INFO: This request was sent: {
"state": "SUCCESSFUL",
"key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"url": "http://XX.XX.XX.XX:8080/job/XXXXXX/16/",
"name": "XXXXXX #XX"
}
Mar 15, 2018 3:55:07 AM org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper sendBuildStatusNotification
INFO: This response was received: {"key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "description": "", "repository": {"links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/XXXXXXXXXX/XXXXXXX"}, "html": {"href": "https://bitbucket.org/XXXXXXXXXX/XXXXXXX"}, "avatar": {"href": "https://bitbucket.org/XXXXXXXXXX/XXXXXXX/avatar/32/"}}, "type": "repository", "name": "XXXXXXX", "full_name": "XXXXXXXXXX/XXXXXXX", "uuid": "{XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX}"}, "url": "http://XX.XX.XX.XX:8080/job/XXXXXX/XX/", "links": {"commit": {"href": "https://api.bitbucket.org/2.0/repositories/XXXXXXXXXX/XXXXXXX/commit/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}, "self": {"href": "https://api.bitbucket.org/2.0/repositories/XXXXXXXXXX/XXXXXXX/commit/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/statuses/build/XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}}, "refname": null, "state": "SUCCESSFUL", "created_on": "2018-03-15T03:55:07.857369+00:00", "commit": {"hash": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "type": "commit", "links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/XXXXXXXXXX/XXXXXXX/commit/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}, "html": {"href": "https://bitbucket.org/XXXXXXXXXX/XXXXXXX/commits/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}}}, "updated_on": "2018-03-15T03:55:07.857429+00:00", "type": "build", "name": "XXXXXXX #XX"}
Mar 15, 2018 3:55:08 AM org.jenkinsci.plugins.workflow.job.WorkflowRun finish
INFO: PR-LGM #16 completed: SUCCESS
The issue is, I see two builds on bitbucket, one is successful with a green tick and the other just remains a pending(blue clock) forever.
Subsequent updates to the PR, keep increasing successful builds but one build remains in the running state forever.
On the jenkins, I get this error.
Mar 15, 2018 3:55:08 AM hudson.model.listeners.RunListener report
WARNING: RunListener failed
java.lang.NullPointerException
at bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketRepository.setBuildStatus(BitbucketRepository.java:153)
at bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketBuilds.onCompleted(BitbucketBuilds.java:46)
at bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.BitbucketBuildListener.onCompleted(BitbucketBuildListener.java:36)
at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:211)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:688)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.access$1400(WorkflowRun.java:143)
at org.jenkinsci.plugins.workflow.job.WorkflowRun$GraphL.onNewHead(WorkflowRun.java:1006)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.notifyListeners(CpsFlowExecution.java:1368)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$3.run(CpsThreadGroup.java:412)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:35)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
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:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Below is the Jenkinsfile definition of the pipeline job.
pipeline {
environment {
LINUX_NODE = ""
}
agent none
[...]
stages {
stage('Staging Code and Dependencies...') {
failFast true
parallel {
stage('Code Checkout') {
agent {
node { label 'linux_slave_machine' }
}
[...]
}
}
}
stage('Running...') {
failFast true
parallel {
stage('Running on Linux') {
agent {
node { label 'linux_slave_machine' }
}
steps {
deleteDir()
script {
LINUX_NODE = "${env.NODE_NAME}"
}
unstash 'code'
echo ("Printing for no reason!")
}
}
}
}
}
post {
success {
bitbucketStatusNotify(buildState: 'SUCCESSFUL')
node("${LINUX_NODE}") {
step([$class: 'WsCleanup'])
}
}
[...]
}
}
Turns out a few old jobs I had created for testing, even when they were disabled, were making Bitbucket wait for their build status notification. As they never ran, Bitbucket never received their status.