user6136315
user6136315

Reputation: 705

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()

Upvotes: 2

Views: 2131

Answers (1)

Yuri G.
Yuri G.

Reputation: 4648

Try this:

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

Upvotes: 4

Related Questions