Is there a way to get a list of RUNNING builds in Jenkins via a System Groovy Script? I tried looping through the busy executors, but from an executor object, I cannot get the build object:
def busyExecutors = Jenkins.instance.computers
.collect {
c -> c.executors.findAll { it.isBusy() }
}
.flatten() // reminder: transforms list(list(executor)) into list(executor)
busyExecutors.each { e ->
println('=====print out methods of executor object=======');
println e.metaClass.methods*.name.sort().unique();
}
I can also target the JOB that I'm interested in like so:
def item = hudson.model.Hudson.instance.getItem("my_job");
println item.metaClass.methods*.name.sort().unique();
But then I will have to loop through 100s (if not more) builds and ask each build if they are running.
There has to be an easier/better way of getting a list of running builds.
There is a lot of information on how to do various things via System Groovy Scripts (some of which I wrote), but I cannot figure out how to get a list of running builds:
How to get currently running job's node name in jenkins using groovy
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console
https://gist.github.com/dnozay/e7afcf7a7dd8f73a4e05
How to make a Jenkins/Hudson job surveil some others jobs and decide whether to build or not?
_getRuns()
– Steven the Easily Amusedimport jenkins.model.Jenkins
at top of script. – gaoithe