首页 > 解决方案 > 脚本化的 Jenkinsfile 并行构建器不起作用

问题描述

我正在尝试在我的脚本 jenkinsfile 中使用并行构建器。当我运行代码时,詹金斯忽略了节点标签,只选择了第一个可用的标签。我究竟做错了什么?

这是代码:

  node {
    withCredentials([
        string(credentialsId: 'some ID', variable: 'some variable')
    ]) {
      stage('Initialize') {
        setup()
      }
    }
  }
}


def setup_worker() {
  def labels = ['label2', 'label1']
  def builders = [:]
  for (x in labels) {
    def label = x
    builders[label] = {
      node(label) {
        stage('Setup') {
          step1
          checkout scm
          login()
          write_config()
        }
      }
    }
  }
  parallel builders
}```

标签: jenkinsjenkins-job-builder

解决方案


我强烈建议使用 Jenkins 声明式管道来处理不同节点上的并行阶段。语法更简单且有据可查

https://jenkins.io/blog/2017/09/25/declarative-1/


推荐阅读