在声明性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}”
}
}
}
}
}
,可用于所有或某些作业
我删除了我的第一个答案,因为它纯粹是废话