Jenkins 如何使用try{}catch{}finally{}

Jenkins 如何使用try{}catch{}finally{},jenkins,jenkins-pipeline,devops,jenkins-groovy,devops-services,Jenkins,Jenkins Pipeline,Devops,Jenkins Groovy,Devops Services,如何对以下脚本使用try{}catch{}? 使用try/catch对我来说有点困惑 stages { stage ('something') { agent any steps { script { something ]) { sh "something" } } } 一个带有try/catch/fin

如何对以下脚本使用
try{}catch{}
? 使用try/catch对我来说有点困惑

stages {
stage ('something') {
    agent any
    steps {
        script {
            something
            ]) {
                sh "something"
            }
        }
    }



 

一个带有try/catch/finally的脚本化管道的简单示例

node('<Node Name>') {
        stage("<Stage Name>") {
            try {
                // Your logic/code
            } catch (Exception ex) {
                // depends what you want to do with the exception
                // You can even suppress the exception means not to fail the build
                // or do something and than throw it
            } finally {
                // whatever you will put here will always gets executed
            }
        }
    }
节点(“”){
阶段(“”){
试一试{
//你的逻辑/代码
}捕获(例外情况除外){
//取决于您要对异常执行的操作
//您甚至可以抑制异常意味着构建不会失败
//或者做点什么然后扔掉它
}最后{
//你放在这里的任何东西都会被执行
}
}
}