bitbucketStatusNotify ** 即使在 Jenkins 作业完成后,基于 bitbucket 的构建也永远不会完成
bitbucketStatusNotify ** Build on the bitbucket never finishes even after Jenkins job finishes
我在 Bitbucket 中配置了 webhooks 以捕获 PR "create"/"update" 事件并在 Jenkins 上执行构建以在 Bitbucket 中提供构建状态。
在 Jenkins 中成功构建 运行 之后(我得到一个蓝色气泡)它通知 Bitbucket 有关构建状态并收到成功响应。
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
问题是,我在 bitbucket 上看到两个构建,一个成功并带有绿色勾号,另一个只是永远处于待定状态(蓝色时钟)。
PR 的后续更新,不断增加成功的构建,但一个构建永远保持 运行 状态。
在 jenkins 上,我得到这个错误。
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.access00(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.run(CpsThreadGroup.java:412)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService.run(CpsVmExecutorService.java:35)
at hudson.remoting.SingleLaneExecutorService.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService.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)
下面是管道作业的 Jenkinsfile 定义。
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'])
}
}
[...]
}
}
原来我为测试创建的一些旧作业,即使它们被禁用,也会让 Bitbucket 等待它们的构建状态通知。由于他们从未 运行,Bitbucket 从未收到他们的状态。
我在 Bitbucket 中配置了 webhooks 以捕获 PR "create"/"update" 事件并在 Jenkins 上执行构建以在 Bitbucket 中提供构建状态。
在 Jenkins 中成功构建 运行 之后(我得到一个蓝色气泡)它通知 Bitbucket 有关构建状态并收到成功响应。
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
问题是,我在 bitbucket 上看到两个构建,一个成功并带有绿色勾号,另一个只是永远处于待定状态(蓝色时钟)。
PR 的后续更新,不断增加成功的构建,但一个构建永远保持 运行 状态。
在 jenkins 上,我得到这个错误。
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.access00(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.run(CpsThreadGroup.java:412)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService.run(CpsVmExecutorService.java:35)
at hudson.remoting.SingleLaneExecutorService.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService.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)
下面是管道作业的 Jenkinsfile 定义。
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'])
}
}
[...]
}
}
原来我为测试创建的一些旧作业,即使它们被禁用,也会让 Bitbucket 等待它们的构建状态通知。由于他们从未 运行,Bitbucket 从未收到他们的状态。