Determine if given job is currently running using Hudson/Jenkins API

前端 未结 5 947
忘掉有多难
忘掉有多难 2020-12-29 05:24

Is there an API to determine whether a given job is currently running or not?

Ideally, I\'d also like to be able to determine its estimated % complete and get the de

5条回答
  •  醉话见心
    2020-12-29 05:56

    I'm using the Groovy plug-in, and run the following snippet as system:

    import hudson.model.*
    def version = build.buildVariableResolver.resolve("VERSION")
    println "VERSION=$version"
    def nextJobName = 'MY_NEXT_JOB'
    def nextJob = Hudson.instance.getItem(nextJobName)
    def running = nextJob.lastBuild.building
    if (running) {
       println "${nextJobName} is already running. Not launching"
    } else {
       println "${nextJobName} is not running. Launching..."
       def params = [
          new StringParameterValue('VERSION', version)
       ]
       nextJob.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params))
    }
    

    It works like a charm.

提交回复
热议问题