How to get a list of all Jenkins nodes assigned with label including master node?

Updated answer: in a pipeline use nodesByLabel to get all nodes assigned to a label.


This is the way I'm doing it right now. I haven't found anything else:

@NonCPS
def hostNames(label) {
  def nodes = []
  jenkins.model.Jenkins.get().computers.each { c ->
    if (c.node.labelString.contains(label)) {
      nodes.add(c.node.selfLabel.name)
    }
  }
  return nodes
}

jenkins.model.Jenkins.get.computers contains the master-node and all the slaves.