【问题标题】:Better visualization of skipped stages in declarative pipeline更好地可视化声明性管道中跳过的阶段
【发布时间】:2017-03-23 09:45:49
【问题描述】:

我正在考虑将我们的脚本化管道迁移到声明性管道。

我使用 when 关键字跳过阶段

stage('test') {       
     // Only do anything if we are on the master branch
     when { branch 'master' }
     //...
}

这可行,但是跳过的阶段显示为绿色。我希望它在管道概述中显示为灰色。有没有办法做到这一点?

【问题讨论】:

标签: jenkins jenkins-pipeline


【解决方案1】:

正如您在评论中提到的,我建议您在使用管道时使用Jenkins Blue Ocean

它为您的管道项目提供了更现代和用户友好的视图。甚至管道本身也以更方便的方式显示。

【讨论】:

    【解决方案2】:

    如果舞台对您来说是绿色的,那么它很可能实际上仍在运行。跳过的阶段should look like this in the Jenkins classic stage view。考虑以下代码示例,它具有三个阶段,中间阶段使用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
    

    这个问题的另一个回答者提到了蓝海,它绝对呈现了一个美丽的舞台景观。 Here is an image of how a skipped stage looks in the Blue Ocean stage view。请注意,Blue Ocean 是一个 UI,无论您选择使用哪个 UI,您的作业的底层管道代码都是相同的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-29
      • 2021-03-18
      • 2021-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多