我正在考虑将我们的脚本化管道转移到声明式管道。
我使用when关键字来跳过阶段
stage('test') {
// Only do anything if we are on the master branch
when { branch 'master' }
//...
}
这有效,但是跳过的阶段显示为绿色。我希望它在管道概述中显示为灰色。有没有办法实现这个目标?
正如您在评论中提到的,我建议您在使用管道时使用Jenkins Blue Ocean。
它为您的管道项目提供了更现代、更用户友好的视图。甚至管道本身也以更方便的方式显示。
如果舞台对您来说显示为绿色,那么它实际上可能仍在运行。跳过的阶段在 Jenkins 经典阶段视图中应该像这样。考虑以下代码示例,它具有三个阶段,使用
when
指令有条件地跳过中间阶段。
pipeline {
agent any
stages {
stage('Always run 1') {
steps { echo "hello world" }
}
stage('Conditionally run') {
when {
expression { return false }
}
steps { echo "doesn't get printed" }
}
stage("Always run 2") {
steps { echo "hello world again" }
}
}
}
这应该在您的构建日志中生成以下行
Stage "Conditionally run" skipped due to when conditional
这个问题的另一个回答者提到了《蓝海》,这绝对是一个美丽的舞台景观呈现。 这是蓝海舞台视图中跳过的舞台的外观图像。请注意,Blue Ocean 是一个 UI,无论您选择使用哪个 UI,您的作业的底层管道代码都将是相同的。
我有与跳过阶段相关的查询。有什么办法可以跳过舞台也不在海景下显示/观看吗?