title: How to get a list of running jenkins builds via groovy script?
body: <p>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:</p>
  
  <pre><code>def busyExecutors = Jenkins.instance.computers
                                  .collect { 
                                    c -&gt; c.executors.findAll { it.isBusy() }
                                  }
                                  .flatten() // reminder: transforms list(list(executor)) into list(executor)
  
  busyExecutors.each { e -&gt; 
    println('=====print out methods of executor object=======');
    println e.metaClass.methods*.name.sort().unique();
  
  }
  </code></pre>
  
  <p>I can also target the JOB that I'm interested in like so:</p>
  
  <pre><code>def item = hudson.model.Hudson.instance.getItem("my_job");
  println item.metaClass.methods*.name.sort().unique(); 
  </code></pre>
  
  <p>But then I will have to loop through 100s (if not more) builds and ask each build if they are running.</p>
  
  <p>There has to be an easier/better way of getting a list of running builds.</p>
  
  <p>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:</p>
  
  <p><a href="https://stackoverflow.com/questions/29831720/how-to-get-currently-running-jobs-node-name-in-jenkins-using-groovy">How to get currently running job&#39;s node name in jenkins using groovy</a></p>
  
  <p><a href="https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console" rel="noreferrer">https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console</a></p>
  
  <p><a href="https://gist.github.com/dnozay/e7afcf7a7dd8f73a4e05" rel="noreferrer">https://gist.github.com/dnozay/e7afcf7a7dd8f73a4e05</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10777663/how-to-make-a-jenkins-hudson-job-surveil-some-others-jobs-and-decide-whether-to">How to make a Jenkins/Hudson job surveil some others jobs and decide whether to build or not?</a></p>