jenkins 如何最终使用try{} catch{}{}

pvcm50d1  于 2022-12-22  发布在  Jenkins
关注(0)|答案(1)|浏览(135)

如何在下面的脚本中使用try { } catch { }?使用try/catch对我来说有点混乱

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

owfi6suc1#

使用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
            }
        }
    }

相关问题