从Jenkins管道获取失败原因 [英] Get failure reason from Jenkins pipeline
问题描述
我正在为詹金斯建立一个声明式管道.在我的post
部分中,我正在使用slackSend
通知我的团队该版本已损坏.我想包括失败原因.在env
或currentBuild
或其他版本中可用吗?我没有在文档中看到任何内容,但似乎是一个常见的用例
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屋!