// 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
build job: 'PayloadJob', parameters: [
new org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue
("TARGET_NODE", "description", 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 }
}
启用 This project is parameterized ,添加 Label 类型的参数,输入标签的任意名称并选择默认值,例如覆盖多个节点的标签或此类标签的结合(&&) . 启用 Run on all nodes matching the label ,保持 Run regardless of result ,将 Node eligibility 保留在 All nodes .
8 回答
您需要两个插件:Paramitrized Trigger Plugin能够触发其他作业作为主要作业的构建步骤,并且NodeLabel Plugin(阅读BuildParameterFactory部分以了解您需要的内容)以指定标签 .
Rundeck可能是一个更适合您需求的工具 . 可以设置为并行运行多个作业,并有一个Jenkins插件:http://rundeck.org/
Rundeck旨在与更大的系统集成 . 我们从配置管理数据库生成资源文件 . 很容易看到文档:http://rundeck.org/docs/administration/node-resource-sources.html .
另外可用于亚马逊和/或木偶和厨师系统的插件:http://rundeck.org/plugins
矩阵构建将起作用;使用“Slaves”作为轴并展开“Individual nodes”列表以选择所有节点 .
请注意,每次添加或删除从站时都需要更新选择 .
对于更易于维护的解决方案,您可以使用Job DSL plugin设置具有构建模板的种子作业,然后遍历每个从属并创建新作业,并将构建标签设置为从属名称 .
安装
Parameterized Trigger Plugin
NodeLabel Parameter Plugin
对于要运行的作业,请根据需要启用“执行并发构建”
除了要在所有从站上运行的作业之外,创建另一个作业并进行配置
构建>添加构建步骤>在其他项目上触发/调用构建
添加ParameterFactories>标签工厂的所有节点>标签:节点的标签
最好和最简单的方法是使用Elastic Axis插件 .
1.安装喷嘴 .
2.创建多配置作业 . (如果不存在则安装)
3.在作业配置中,您可以找到添加为弹性轴的新轴 . 添加如下所示的标签,以便在多个从站上运行作业 .
知道了 - 不需要任何特殊的插件!
我打电话给他,我告诉他 Label 我不想继续工作 .
所以基本上父作业只触发我需要的工作,子作业将运行的次数与 Label 中的从属数量一样多(在我的情况下为4次) .
取以上几个答案并将其调整为2.0系列 .
您现在可以在所有节点上启动所有作业 .
取自代码https://jenkins.io/doc/pipeline/examples/#trigger-job-on-all-nodes
启用
This project is parameterized
,添加Label
类型的参数,输入标签的任意名称并选择默认值,例如覆盖多个节点的标签或此类标签的结合(&&) . 启用Run on all nodes matching the label
,保持Run regardless of result
,将Node eligibility
保留在All nodes
.