在脚本管道中跳过的例外

发布于 2025-02-10 19:59:53 字数 213 浏览 1 评论 0原文

我有一个带有这样的代码的脚本詹金斯管道。

func_stage_1() {
    try {
        stage1
    } catch {
    }
}
func_stage_1()

最初,当我没有内部功能的阶段时,如果阶段失败并打印了异常,则管道曾经失败。将其放入功能之后,即使一个阶段失败,它仍会继续整个管道。如何解决这个问题?

I have a scripted jenkins pipeline with the code like this.

func_stage_1() {
    try {
        stage1
    } catch {
    }
}
func_stage_1()

Initially when I did not have the stage inside function, pipeline used to fail if a stage failed and exceptions were printed. After putting it inside function, it continues the whole pipeline even though one stage fails. How to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記柔刀 2025-02-17 19:59:53

添加异常逻辑背后的主要功能是继续该过程,即使阶段失败了。

如果要使剩余过程停止,如果发生异常,则必须以下面的方式进行。

func_stage_1() {
    try {
        stage1
    } catch(Exception err {
         error "${err}" // stops the execution of remaining stages by throwing the exception
    }
}
func_stage_1()

Main functionality behind adding exception logic is to continue the process even though the stage is failed.

If you want to make the remaining process stop, if exception occurred then you have to do it in below way.

func_stage_1() {
    try {
        stage1
    } catch(Exception err {
         error "${err}" // stops the execution of remaining stages by throwing the exception
    }
}
func_stage_1()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文