Try-catch block in Jenkins pipeline script

后端 未结 5 1675
有刺的猬
有刺的猬 2020-12-13 18:16

I\'m trying to use the following code to execute builds, and in the end, execute post build actions when builds were successful. Still, I get a MultipleCompilationErrorsExce

5条回答
  •  伪装坚强ぢ
    2020-12-13 18:53

    Look up the AbortException class for Jenkins. You should be able to use the methods to get back simple messages or stack traces. In a simple case, when making a call in a script block (as others have indicated), you can call getMessage() to get the string to echo to the user. Example:

    script {
            try {
                sh "sudo docker rmi frontend-test"
            } catch (err) {
                echo err.getMessage()
                echo "Error detected, but we will continue."
            }
            ...continue with other code...
    }
    

提交回复
热议问题