Jenkins声明式管道获取构建失败原因[重复]。

问题描述 投票:0回答:1

我最近将一个脚本管道转换为声明式管道,但在构建失败案例中遇到了麻烦。岗位 部分。

对于一个脚本管道,我可以很容易地将管道包裹在一个叫做 捉迷藏 并可以访问异常对象。但对于像这样的声明式管道来说,就不一样了。

pipeline {
    stages {
        ...
    }
    post{
        failure {
            script {
                //this is where i need the failure exception detail
                handleFailure()
            }
        }
    }
}

我不知道该怎么做,我在尝试... getContext() 方法,但它返回 无效 .感谢任何建议。

jenkins jenkins-plugins jenkins-declarative-pipeline
1个回答
0
投票
//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'
                     }
                   }
               }
           }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.