0

我在 Bitbucket 中配置了 webhook 以捕获 PR“创建”/“更新”事件并在 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 的后续更新,不断增加成功的构建,但一个构建永远保持在运行状态。

在詹金斯上,我收到了这个错误。

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)

下面是管道作业的 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'])
      }
    }
    [...]
  }
}
4

1 回答 1

0

结果发现,我为测试创建的一些旧作业,即使它们被禁用,也让 Bitbucket 等待它们的构建状态通知。由于它们从未运行过,因此 Bitbucket 从未收到它们的状态。

于 2018-05-28T09:54:52.553 回答