简体   繁体   中英

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. 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 . 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. Let's take the below example:

Previous old builds

Build #1 - Complete

Build #2 - Failed

Build #3 - Complete

Build #4 - Complete

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 . But this code checks for all the builds (Build #1 to Build #5) to be in the Complete status. Because of that, the pipeline waits until all 5 builds are Complete and eventually times out and jenkins build fails.

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.

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.

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

This will return a non-zero code if the build fails and the stage will also fail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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