user6136315 user6136315 - 3 months ago 39
Groovy Question

List total number of current builds running for a job on Jenkins

I would like to monitor how many concurrent builds running for a job on Jenkins using groovy script console.

Using this I'm able to get the last build status. I need to get the count of current builds that are running. Can someone help me on this?

def item = hudson.model.Hudson.instance.getItem("<JOB-NAME>")
def build = item.getLastBuild()

println build.isInProgress()

Answer

Try this:

jenkins.model.Jenkins.getInstance()
                     .getItem("<JOB-NAME>")
                     .getBuilds()
                     .findAll(
                         {
                            it.isInProgress()
                         }
                     )
Comments