问题描述
如何为以下脚本使用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
}
}
}