title: How to get a list of all Jenkins nodes assigned with label including master node?
body: <p>I'm creating a Jenkins pipeline job and I need to run a job on all nodes labelled with a certain label.</p>
  <p>Therefore I'm trying to get a list of node names assigned with a certain label. (With a node I can get the labels with <code>getAssignedLabels()</code>)</p>
  <p>The <code>nodes</code>-list in <code>jenkins.model.Jenkins.instance.nodes</code> seems not contain the master-node which I need to include in my search.</p>
  <p>My current solution is to iterate over the <code>jenkins.model.Jenkins.instance.computers</code> and use the <code>getNode()</code>-method to get the node. This works, but in the javadoc of Jenkins I'm reading the this list might not be up-to-date.</p>
  <p>In the long-run I will add (dynamically) cloud-nodes and I'm afraid that I won't be able to use <code>computers</code> then.</p>
  <p>What is the right way to get the list of all current nodes?</p>
  <p>This is what I'm doing right now:</p>
  <pre><code>@NonCPS
  def nodeNames(label) {
      def nodes = []
      jenkins.model.Jenkins.instance.computers.each { c -&gt;
          if (c.node.labelString.contains(label)) {
              nodes.add(c.node.selfLabel.name)
          }
      }   
      return nodes
  }
  </code></pre>