Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在声明性jenkins中的阶段步骤内并行运行_Jenkins_Groovy_Jenkins Pipeline_Jenkins Declarative Pipeline - Fatal编程技术网

在声明性jenkins中的阶段步骤内并行运行

在声明性jenkins中的阶段步骤内并行运行,jenkins,groovy,jenkins-pipeline,jenkins-declarative-pipeline,Jenkins,Groovy,Jenkins Pipeline,Jenkins Declarative Pipeline,所以,我想在一个阶段内运行我的并行阶段,但我也想在每个并行阶段编写一些共享代码,这些代码是我在并行父阶段的步骤中编写的 我面临的问题是并行阶段没有运行 stages { stage('partent stage 1'){ something here } stage('parent stage 2') { steps { // common code for parallel stages parallel {

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

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

      }
   }
}

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

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}”
        }
      }
    }
  }
}
,可用于所有或某些作业


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

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

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}”
        }
      }
    }
  }
}
,可用于所有或某些作业

我删除了我的第一个答案,因为它纯粹是废话