Jenkins声明式管道语法中如何继续经历失败的阶段 [英] How to continue past a failing stage in Jenkins declarative pipeline syntax

查看:126
本文介绍了Jenkins声明式管道语法中如何继续经历失败的阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Jenkins声明式管道语法中定义多个阶段,这些阶段可以继续通过其中任何一个失败的阶段.我找不到任何真正重复的问题,因为它们全部采用或允许使用脚本语法.

pipeline {
    agent any
    stages {
        stage('stage 1') {
            steps {
                echo "I need to run every time"
            }
        }
        stage('stage 2') {
            steps {
                echo "I need to run every time, even if stage 1 fails"
            }
        }
        stage('stage 3') {
            steps {
                echo "Bonus points if the solution is robust enough to allow me to continue *or* be halted based on previous stage status"
            }
        }
    }
}

为了澄清,我不是在寻找如何通过脚本语法来完成此任务.我试图了解这种流控制是否实际上以声明性语法得到支持和形式化.为此,我将尝试准确定义我要查找的内容:

必需

  • 不尝试/抓住.我不想进入脚本模式,也不想将我的声明式管道包装"在另一个共享库或脚本块中.
  • post step恶作剧.我想要真正的多个阶段,而不是一个包含所有其他逻辑的post always步骤的阶段

可选

  • 失败阶段应被视为失败;我不希望失败的阶段显示为绿色,因为它已跳过"或继续".
  • 阶段失败的构建应标记为红色(或黄色或任何非绿色的标记).

相关但不充分

解决方案

我可能遗漏了一些东西,但是声明性的意见管道的想法是提供大多数简单用例的覆盖范围. 当您需要已处理尚未解决的内容时,您必须诉诸脚本化管道,这仅是指声明性管道"的要求":现在不会发生.

对于您的其他需求",它们没有什么意义,因为整个想法是将低级丑陋包装到共享库中,从而为用户提供以下构造:

    mylib.failable_stages({
      stages {
        stage('stage 1') {
          steps {
            echo "I need to run every time"
          }
        }
        stage('stage 2') {
          steps {
            echo "I need to run every time, even if stage 1 fails"
          }
        }
        stage('stage 3') {
          steps {
            echo "Bonus points if the solution is robust enough to allow me to continue *or* be halted based on previous stage status"
          }
        }
      }
    })

自然地,您将不得不找到或实现这样的mylib类,而failable_stages将获得一个闭包,并将其包装在各种管道/样板代码段中.

希望这会有所帮助.

I want to define multiple stages in Jenkins declarative pipeline syntax which can continue past any one of them failing. I cannot find any existing questions which are true duplicates, because they all assume or allow scripted syntax.

pipeline {
    agent any
    stages {
        stage('stage 1') {
            steps {
                echo "I need to run every time"
            }
        }
        stage('stage 2') {
            steps {
                echo "I need to run every time, even if stage 1 fails"
            }
        }
        stage('stage 3') {
            steps {
                echo "Bonus points if the solution is robust enough to allow me to continue *or* be halted based on previous stage status"
            }
        }
    }
}

To clarify, I'm not looking for how to do accomplish this in scripted syntax. I'm trying to understand if this kind of flow control is actually supported and formalized in declarative syntax. To that end, I'll try to define exactly what I'm looking for:

Required

  • No try/catch. I don't want to drop down into scripted mode, or "wrap" my declarative pipeline in another shared library or scripted block.
  • No post step shenanigans. I want true multiple stages, not one stage with a post always step that contains all my other logic

Optional

  • The failing stage should be recognized as failed; I don't want a failed stage showing up as green because it was "skipped" or "continued".
  • A build with any failed stage should be marked as red (or yellow, or anything that is not green).

Related but Not Sufficient

解决方案

I may be missing something, but the idea of declarative, opinionated pipeline is to provide coverage of most simple use cases. The moment you need something the opinionated hasn't covered, you HAVE to resort to scripted pipeline, this is only referring to the "requirement" of "declarative pipeline": not going to happen now.

As to your other "requirements", they make very little sense, since the whole idea is to wrap low-level ugliness into shared libraries providing users with constructs like:

    mylib.failable_stages({
      stages {
        stage('stage 1') {
          steps {
            echo "I need to run every time"
          }
        }
        stage('stage 2') {
          steps {
            echo "I need to run every time, even if stage 1 fails"
          }
        }
        stage('stage 3') {
          steps {
            echo "Bonus points if the solution is robust enough to allow me to continue *or* be halted based on previous stage status"
          }
        }
      }
    })

Naturally, you would have to find or implement such mylib class and the failable_stages would get a closure, and wrap it in various plumbing/boilerplate code pieces.

Hope this is helpful.

这篇关于Jenkins声明式管道语法中如何继续经历失败的阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆