本文介绍了Jenkins声明式管道获取构建失败原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近将脚本化管道转换为声明性管道,但是在 post 部分中无法获取构建失败案例.
I recently converted a scripted pipeline into a declarative pipeline but having trouble to get the build failure case in the post section.
对于脚本化管道,我可以轻松地将管道包装在 try-catch 中,并可以访问异常对象.但不适用于这样的声明性管道:
For a scripted pipeline, I can easily wrap the pipeline inside a try-catch and have access to the exception object. But not for declarative pipeline like this:
pipeline {
stages {
...
}
post{
failure {
script {
//this is where i need the failure exception detail
handleFailure()
}
}
}
}
我不确定该怎么做,我正在尝试 getContext()方法,但它返回 null .感谢任何建议.
Im not sure how to do that, I'm trying getContext() method but it return null .Appreciate any suggestion.
推荐答案
//proceed to next stage based on the currentBuild.result
def currentBuild.result='';
pipeline
{
stages
{
stage('example')
{
steps
{
script
{
try
{
\\ render the code here
currentBuild.result='SUCCESS'
}
catch(Exception ex)
{
println(ex)
currentBuild.result='FAILURE'
}
}
}
}
}
}
这篇关于Jenkins声明式管道获取构建失败原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!