Can I create dynamically stages in a Jenkins pipeline?

后端 未结 6 1605
南方客
南方客 2020-12-04 15:25

I need to launch a dynamic set of tests in a declarative pipeline. For better visualization purposes, I\'d like to create a stage for each test. Is there a way to do so?

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 15:53

    You might want to take a look at this example - you can have a function return a closure which should be able to have a stage in it.

    This code shows the concept, but doesn't have a stage in it.

    def transformDeployBuildStep(OS) {
        return {
            node ('master') { 
            wrap([$class: 'TimestamperBuildWrapper']) {
    ...
            } } // ts / node
        } // closure
    } // transformDeployBuildStep
    
    stage("Yum Deploy") {
      stepsForParallel = [:]
      for (int i = 0; i < TargetOSs.size(); i++) {
          def s = TargetOSs.get(i)
          def stepName = "CentOS ${s} Deployment"
          stepsForParallel[stepName] = transformDeployBuildStep(s)
      }
      stepsForParallel['failFast'] = false
      parallel stepsForParallel
    } // stage
    

提交回复
热议问题