简体   繁体   English

使用 untilEach openshift jenkins 客户端插件检查 openshift 中上次构建的状态

[英]Check status of last build in openshift using untilEach openshift jenkins client plugin

I want to check the latest build status using the openshift jenkins client plugin.我想使用 openshift jenkins 客户端插件检查最新的构建状态。 Following the official documentation here按照这里的官方文档

stage('Start build') {
  steps {
    script {
      openshift.withCluster() {
        openshift.withProject('my-project') {
          openshift.selector("bc", "app_name").startBuild()
        }
      }
    }
    script {
      openshift.withCluster() {
        openshift.withProject('my-project') {
          def builds = openshift.selector("bc", "app_name").related('builds')
          timeout(5) {
            builds.untilEach(1) {
              return (it.object().status.phase == "Complete")
            }
          }
        }
      }
    }
  }
}

The above code starts a new build and then checks for all related builds ' status to the build config .上面的代码开始一个新的构建,然后检查所有相关builds的状态到build config I want it to check the status of the build that was started.我希望它检查已启动的构建的状态。

It checks for all the previous related builds' status to be Complete too.它也检查所有先前相关构建的状态是否Complete Let's take the below example:让我们看下面的例子:

Previous old builds以前的旧版本

Build #1 - Complete构建 #1 - 完成

Build #2 - Failed构建 #2 - 失败

Build #3 - Complete构建 #3 - 完成

Build #4 - Complete构建 #4 - 完成

When I execute the pipeline in Jenkins - A new Build #5 gets started and I want the above code to only check for the status of Build #5 to be Complete .当我在 Jenkins 中执行管道时 - 一个新的Build #5开始,我希望上面的代码只检查Build #5的状态为Complete But this code checks for all the builds (Build #1 to Build #5) to be in the Complete status.但是此代码检查所有构建(构建#1 到构建#5)是否处于Complete状态。 Because of that, the pipeline waits until all 5 builds are Complete and eventually times out and jenkins build fails.因此,管道会等待所有 5 个构建Complete并最终超时,并且 jenkins 构建失败。

I only want it to check the status of the latest (last) build.我只希望它检查最新(最后)构建的状态。 The documentation doesn't have an example of that, but it should be possible.该文档没有这方面的示例,但应该是可能的。 I can vaguely understand it must be possible by using watch but not sure how to execute it.我可以模糊地理解它必须通过使用watch来实现,但不知道如何执行它。

Appreciate your help.感谢你的帮助。

After much research turns out the answer was right there in front of my face.经过大量研究,答案就在我面前。 Just add the "--wait" argument in the previous startBuild step.只需在前面的startBuild步骤中添加"--wait"参数即可。

openshift.selector("bc", "app_name").startBuild("--wait")

This will return a non-zero code if the build fails and the stage will also fail.如果构建失败并且stage也将失败,这将返回一个非零代码。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM