我的管道有问题。 (詹金斯版本1.165.1)
我有:
管道(下面列出了2个阶段,每个参数化构建一个阶段)。 每个参数化构建运行3次,每个客户端一次。 在每个阶段中,3个客户端可以并行运行。
但是,我希望Stage#2仅在Stage#1的所有3个版本完成并且已成功完成后运行。 我的问题是,只要阶段#1的所有构建都已启动,阶段#2就会开始。
阶段#2不考虑这些构建的最终状态...... 因此,阶段#2在阶段#1的构建正在进行时开始,并且它导致错误。
FWIW,使用具有硬编码客户端值的构建实际上解决了这个问题。但我需要使用参数化构建。 我们有超过3个客户和2个构建工作。硬编码的构建会导致构建数量的扩散。
我怎样才能让阶段#2(在管道中)知道阶段#1构建的结果?只有在第1阶段的构建成功后才能继续?
我正在考虑的解决方案包括在参数化构建中使用预操作和后期操作来读取/写入DB表的状态。 但这感觉很笨,我认为Jenkins可能有一些更简单的机制来处理这种情况。
你们中有没有人能够实现这样的目标吗?
由于
registerBackButtonAction
答案 0 :(得分:0)
我不确定您的管道示例的语法是否正确 - 看起来您在每个stage
之后错过了大括号。此外,stage
的当前语法没有concurrency
选项(我很清楚。
而不是concurrency
,您想要的是parallel
步骤,并在wait: true
来电时使用build
(默认)。
/* Jenkins Pipeline in Groovy */
def clientlist = ['AAA', 'BBB', 'CCC']
def deployPrep = [:]
def deployTarget = [:]
// Create a map of name-closure pairs
for(item in clientlist)
{
// Closures will be executed later by "parallel" step later in pipeline
deployPrep[item] = {
// "wait: true" is the default
build job: 'Deploy_PrepDB_SHELL',
parameters: [[$class: 'StringParameterValue', name: 'CLIENT_NAME', value: item]]
// Probably don't need this sleep, but including for parity
Thread.sleep(1000)
}
// We can build up multiple maps using one loop.
// Closures will be executed later by "parallel" step later in pipeline
deployTarget[item] = {
build job: 'Deploy_TargetDB_SHELL',
parameters: [[$class: 'StringParameterValue', name: 'CLIENT_NAME', value: item]]
Thread.sleep(1000)
}
}
/*
Stage #1
*/
stage ('1. Deploying Prep Database') {
echo 'Deploying Prep Database DacPac'
parallel deployPrep
}
/*
Stage #2
Will not start until all 3 builds from previous stage have successfully finished!
*/
stage ('2. Deploying Target Database') {
echo 'Deploying Target Database DacPac'
parallel deployTarget
}