Jenkinsfile:在具有相同标签的所有代理中运行任务

Jenkinsfile:在具有相同标签的所有代理中运行任务,jenkins,groovy,jenkins-pipeline,Jenkins,Groovy,Jenkins Pipeline,我想在Jenkins管道中使用相同标签的所有代理运行一个特定任务。为此,我得到了以下代码。但它并没有像预期的那样发挥作用。 它只在标签为“my_label”的第一个从机中运行,然后退出。我需要在所有有这个标签的詹金斯奴隶身上运行这个任务 任何帮助都将不胜感激 def labels=[“我的标签”]def builders=[:]for(标签中的x){ def label=x构建器[label]={ 节点(标签){ //应该在所有节点上执行的构建步骤转到此处 //步骤4 阶段('在给定环境中的所有

我想在Jenkins管道中使用相同标签的所有代理运行一个特定任务。为此,我得到了以下代码。但它并没有像预期的那样发挥作用。 它只在标签为“my_label”的第一个从机中运行,然后退出。我需要在所有有这个标签的詹金斯奴隶身上运行这个任务

任何帮助都将不胜感激

def labels=[“我的标签”]def builders=[:]for(标签中的x){
def label=x构建器[label]={
节点(标签){
//应该在所有节点上执行的构建步骤转到此处
//步骤4
阶段('在给定环境中的所有代理上运行部署'){
sh“echo运行部署”sh“echo发布版本=${params.release\u version}”sh“echo环境=${params.environment}”
}
}
}
}
并行构建器
谢谢,
Arun S

我找到了这段代码,它符合您的要求。但是,您需要取消选中“沙盒”

// The script triggers PayloadJob on every node.
// It uses Node and Label Parameter plugin to pass the job name to the payload job.
// The code will require approval of several Jenkins classes in the Script Security mode
def branches = [:]
def names = nodeNames()
for (int i=0; i<names.size(); ++i) {
  def nodeName = names[i];
  // Into each branch we put the pipeline code we want to execute
  branches["node_" + nodeName] = {
    node(nodeName) {
      echo "Triggering on " + nodeName
    }
  }
}

// Now we trigger all branches
parallel branches

// This method collects a list of Node names from the current Jenkins instance
@NonCPS
def nodeNames() {
  return jenkins.model.Jenkins.instance.nodes.collect { node -> node.name }
}
//该脚本在每个节点上触发PayloadJob。
//它使用节点和标签参数插件将作业名称传递给有效负载作业。
//该代码需要在脚本安全模式下批准几个Jenkins类
def分支=[:]
def名称=节点名称()
对于(int i=0;i node.name}
}