从Jenkins管道获取失败原因 [英] Get failure reason from Jenkins pipeline

查看:641
本文介绍了从Jenkins管道获取失败原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为詹金斯建立一个声明式管道.在我的post部分中,我正在使用slackSend通知我的团队该版本已损坏.我想包括失败原因.在envcurrentBuild或其他版本中可用吗?我没有在文档中看到任何内容,但似乎是一个常见的用例

I'm setting up a declarative pipeline for Jenkins. In my post section, I am using slackSend to notify my team that the build is broken. I'd like to include the failure reason. Is this available in env or currentBuild or something else? I haven't seen anything in the documentation, but seems like a common use case

我已经看到了一些有关使用currentBuild.rawBuild.getLog(10)的文章,并且可以使用,但是其中包含了太多的信息.我需要将实际异常归零

I've seen some posts about using currentBuild.rawBuild.getLog(10) and that works, but it is just filled with way too much information. I need to zero in on the actual exception

推荐答案

另一种方法是使用catchError 或至少 a try/catch .
然后,作为在此答案中,您会收到错误消息:String error = "${e}";

Another approach is to use a catchError or at least a try/catch.
Then, as in this answer, you can get the error message: String error = "${e}";

关于catchError,您会将可能潜在失败的每个步骤包装到catchError函数中.如果发生错误,则会将build.result设置为FAILURE,然后继续执行 .

Regarding catchError, you would wrap every step that can potentially fail into a catchError function. If an error occurs, it will set build.result to FAILURE, and continue the build.

请参见

See catchError, which points out that only the try/catch approach might be useful to catch the actual error e (and its string).
You might then add that error string to a global variable, that your post step could then access.
That would be less verbose and/or more precise than currentBuild.rawBuild.getLog(10).

这篇关于从Jenkins管道获取失败原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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