I\'m creating a Jenkins pipeline job and I need to run a job on all nodes labelled with a certain label.
Therefore I\'m trying to get a list of node names assigned with
Update to @patrick-b answer : contains can be buggy if you have labels containing same string, I've added a split step do check every label separated with spaces.
@NonCPS
def hostNames(label) {
def nodes = []
jenkins.model.Jenkins.get.computers.each { c ->
c.node.labelString.split(/\s+/).each { l ->
if (l != null && l.equals(label)) {
nodes.add(c.node.selfLabel.name)
}
}
}
return nodes
}