view raw
user2257530 user2257530 - 5 months ago 81
Groovy Question

How to list Jenkins projects/jobs in system groovy only on master node?

How to list projects/job names in system Groovy only on master node?
To be more specific:

I need only list of jobs which runs on master! I don't want output any job which runs on slave nodes!


How to list all jobs that has run on master, not that will be run on master... This script only checks the jobs that has actually run and isnt't removed/cleaned up.

import hudson.model.*

jenkins = Hudson.instance

items = jenkins.items

for (item in items){
  def job = item.getLastBuild()
  if(job != null){
        if(job.getBuiltOnStr() == null || job.getBuiltOnStr() == "")
          println "Built on master: " + job.toString()