首页 文章

在所有节点上同时运行Jenkins作业

提问于
浏览
19

我有一大组具有相同标签的节点 . 我希望能够在Jenkins中运行一个在 all 节点上执行的具有相同标签的作业,以及同时执行此操作 .

我看到了在Jenkins中使用矩阵配置选项的建议,但我只能想到一个轴(标签组) . 当我尝试运行该作业时,它似乎只执行一次而不是300次(该标签组中的每个节点都有1次) .

我的另一个轴应该是什么?或者......是否有一些插件可以做到这一点?我曾尝试过NodeLabel参数插件,并选择“在所有可用的在线节点上运行”,但似乎并没有同时运行这些作业 .

8 回答

  • 7

    您需要两个插件:Paramitrized Trigger Plugin能够触发其他作业作为主要作业的构建步骤,并且NodeLabel Plugin(阅读BuildParameterFactory部分以了解您需要的内容)以指定标签 .

  • 12
  • 10

    矩阵构建将起作用;使用“Slaves”作为轴并展开“Individual nodes”列表以选择所有节点 .

    请注意,每次添加或删除从站时都需要更新选择 .

    对于更易于维护的解决方案,您可以使用Job DSL plugin设置具有构建模板的种子作业,然后遍历每个从属并创建新作业,并将构建标签设置为从属名称 .

  • 5
    • 安装

    • Parameterized Trigger Plugin

    • NodeLabel Parameter Plugin

    • 对于要运行的作业,请根据需要启用“执行并发构建”

    • 除了要在所有从站上运行的作业之外,创建另一个作业并进行配置

    • 构建>添加构建步骤>在其他项目上触发/调用构建

    • 添加ParameterFactories>标签工厂的所有节点>标签:节点的标签

  • 7

    最好和最简单的方法是使用Elastic Axis插件 .
    1.安装喷嘴 .
    2.创建多配置作业 . (如果不存在则安装)
    3.在作业配置中,您可以找到添加为弹性轴的新轴 . 添加如下所示的标签,以便在多个从站上运行作业 .
    enter image description here

  • 9

    知道了 - 不需要任何特殊的插件!

    我打电话给他,我告诉他 Label 我不想继续工作 .

    所以基本上父作业只触发我需要的工作,子作业将运行的次数与 Label 中的从属数量一样多(在我的情况下为4次) .

    enter image description here

  • 11

    取以上几个答案并将其调整为2.0系列 .

    您现在可以在所有节点上启动所有作业 .

    // 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 }
    }
    

    取自代码https://jenkins.io/doc/pipeline/examples/#trigger-job-on-all-nodes

  • 1

    启用 This project is parameterized ,添加 Label 类型的参数,输入标签的任意名称并选择默认值,例如覆盖多个节点的标签或此类标签的结合(&&) . 启用 Run on all nodes matching the label ,保持 Run regardless of result ,将 Node eligibility 保留在 All nodes .

    enter image description here

相关问题