Igor Zilberman Igor Zilberman - 1 year ago 127
Groovy Question

How to list jenkins slaves of selected projects

For example, I want to list slaves that are defined in "Foo" jobs: Project_Foo1, Project_Foo2 etc...

def matchedJobs = Jenkins.instance.items.findAll { job ->
job.name =~ /Foo/

I can list projects name, but how to get the slave names?

Answer Source

some groovy way

def matchedJobs = Jenkins.instance.items.findAll{ job -> 
  job.name =~ /test/ && job.getAssignedLabel() != null 
}.collect { job ->
      "${job.name}: ${job.getAssignedLabel().getNodes().collect({it.getNodeName()==""?"master":it.getNodeName()}).join(',')}\n" 
}.each { slaves ->
    println slaves
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download