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

后端 未结 6 1326
囚心锁ツ
囚心锁ツ 2021-02-18 21:25

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

6条回答
  •  渐次进展
    2021-02-18 22:22

    This is the way I'm doing right now. I haven't found something 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.

提交回复
热议问题