gpt4 book ai didi

Jenkins 中止并行阶段

转载 作者:行者123 更新时间:2023-12-04 17:46:07 24 4
gpt4 key购买 nike

如何中止一项并行作业?我必须在 Jenkins 管道中执行应该并行运行的任务。一旦任务 1 完成,任务 2 也应该完成。这可能吗?

pipeline {
agent none
stages {
stage('Stage A') {
agent {
label "winvm01"
}
steps {
script {
stage('Stage 1') {

def branches = [:]

branches["branch_1"] = {
// do some lengthy work
echo "branch 1 ended"
// abort branch 2 here!!??
}

branches["branch_2"] = {
// to something that only should run while branch_1 is running
}
parallel branches
}
}
}
}
}
}

最佳答案

像这样的东西会起作用:

stop = false

parallel 'long': {
sleep 20
println "finished long process"
stop = true
}, 'short': {
while ( !stop ) {
println "work"
sleep 1
}
println "stopped by other branch"
}

您还可以让分支 1 在流程结束时创建一个文件,分支 2 将检查该文件。

如果分支 1 失败并且永远不会满足停止条件,则为分支 2 添加超时可能是个好主意。

编辑:忘记了 failFast: true 标志,这是确保另一个分支停止以防第一个分支失败的更好方法。

关于Jenkins 中止并行阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48497255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com