我最近将一个脚本管道转换为声明式管道,但在构建失败案例中遇到了麻烦。岗位 部分。
对于一个脚本管道,我可以很容易地将管道包裹在一个叫做 捉迷藏 并可以访问异常对象。但对于像这样的声明式管道来说,就不一样了。
pipeline {
stages {
...
}
post{
failure {
script {
//this is where i need the failure exception detail
handleFailure()
}
}
}
}
我不知道该怎么做,我在尝试... getContext() 方法,但它返回 无效 .感谢任何建议。
//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'
}
}
}
}
}
}