【问题标题】:How to run the same pipeline with different parameters in jenkins?如何在詹金斯中运行具有不同参数的相同管道?
【发布时间】:2017-08-07 06:31:31
【问题描述】:

我有一个如下所示的管道脚本:

node {
  try {
    stage('Prepare') {
      // git clone here
    }
    stage('Compile') {
      sh "make ${build_type}"
    }
    stage('Test') {
      sh "./run tests ${build_type}"
    }
  }
  finally {
    if (fileExists("test_results.xml")) {
      junit "test_results.xml"
    }
    emailext subject: "Build finished",
      body: '${JELLY_SCRIPT, template="some-template.template"}',
      to: "some-one@somewhere"
  }
}

${build_type} 可以是“发布”或“调试”。

当我的构建收到触发器时,我希望我的管道为 ${build_type} 中的每个参数运行一次,然后向我发送一封电子邮件,其中包含有关两个构建的报告。

我怎样才能做到这一点?

我尝试在 Compile 阶段定义一个并行块并在那里设置 build_type,但这不会使其他阶段并行运行。

【问题讨论】:

    标签: jenkins jenkins-pipeline


    【解决方案1】:

    希望下面的sn-p可以帮到你。这样,您可以包含多种构建类型 dev、qa、prod。

    def build_types = "dev;qa"
    
    node {
    try {
          stage('Prepare') {
              // git clone here
          }
    
         def buildTypeVar = build_types.tokenize(';')
    
         for(int i=0;i<buildTypeVar.size();i++){
    
            buildType=buildTypeVar.get(i).trim()
    
             stage('Compile ${build_type}') {
                 sh "make ${build_type}"
            }
            stage('Test ${build_type}') {
                sh "./run tests ${build_type}"
            }
        }
    
     }
     finally {
      if (fileExists("test_results.xml")) {
      junit "test_results.xml"
      }
      emailext subject: "Build finished",
        body: '${JELLY_SCRIPT, template="some-template.template"}',
        to: "some-one@somewhere"
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-29
      • 2019-07-04
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多