【发布时间】:2020-01-10 21:02:47
【问题描述】:
我在 Jenkins 中有一个动态脚本流水线,它有许多并行阶段,但在每个阶段中,都有多个串行步骤。我浪费了几天时间试图让它工作:无论我尝试什么,所有串行子阶段都集中在一个阶段! 这是我现在拥有的:
node () {
stage("Parallel Demo") {
// Canonical example to run steps in parallel
// The map we'll store the steps in
def stepsToRun = [:]
for (int i = 1; i < 5; i++) {
stepsToRun["Step${i}"] = { node {
echo "start"
sleep 1
echo "done"
}}
}
// Actually run the steps in parallel
// parallel takes a map as an argument
parallel stepsToRun
}
}
它让我得到了这个漂亮的并行管道:
但是,当我添加一个串行阶段时,又名:
node () {
stage("Parallel Demo") {
// Run steps in parallel
// The map we'll store the steps in
def stepsToRun = [:]
for (int i = 1; i < 5; i++) {
stepsToRun["Step${i}"] = { node {
stage("1") {
echo "start 1"
sleep 1
echo "done 1"
}
stage("2") {
echo "start 2"
sleep 1
echo "done 2"
}
}}
}
// Actually run the steps in parallel
// parallel takes a map as an argument
parallel stepsToRun
}
}
我得到了这个丑陋的东西,看起来完全一样:
为了增加攻击性,我看到了执行的子步骤。如何让我的子步骤显示为阶段?
另外,如果有一种方法可以使声明式管道具有动态阶段(顺序和并行),我完全赞成。我找到了you can do static sequential stages,但不知道如何在不返回脚本管道的情况下使其动态化。
【问题讨论】:
标签: jenkins jenkins-pipeline jenkins-groovy