因此,我想在一个阶段内运行并行阶段,但我也想按每个并行阶段编写一些共享代码,这些代码是在并行父阶段的步骤中编写的 我面临的问题是并行阶段没有运行
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
}
}
}
}
}
答案 0 :(得分:0)
要执行共享代码,您可以在声明式管道之外定义变量和函数:
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。