【问题标题】:Run parallel inside steps of a stage in declarative jenkins在声明式詹金斯的阶段内并行运行
【发布时间】:2020-05-28 11:33:00
【问题描述】:

所以,我想在一个阶段内运行我的并行阶段,但我也想为每个并行阶段编写一些共享代码,这些代码是我在并行父阶段的步骤中编写的 我面临的问题是并行阶段没有运行

stages {
   stage('partent stage 1'){
      something here
   }
   stage('parent stage 2') {
      steps {
         // common code for parallel stages

         parallel {
            stage ('1'){
               // some shell command
            }
            stage('2') {
               // some shell command
            }
         }

      }
   }
}

【问题讨论】:

    标签: jenkins groovy jenkins-pipeline jenkins-declarative-pipeline


    【解决方案1】:

    为了执行共享代码,您可以在声明式管道之外定义变量和函数:

    def foo = true
    
    def checkFoo {
      return foo
    }
    
    pipeline {
      stage('parallel stage') {
        parallel {
          stage('stage 1') {
            steps {
              script {
                def baz = checkFoo()
              }
              sh “echo ${baz}”
            }
          }
          stage('stage 2') {
            steps {
              script {
                def baz = checkFoo()
              }
              sh “echo ${baz}”
            }
          }
        }
      }
    }
    

    You can also write a shared library,您可以在所有或某些工作中使用它。

    我已经删除了我的第一个答案,因为它纯粹是 BS。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 2019-04-08
      相关资源
      最近更新 更多