引言
Jenkins pipeline 脚本,有时因某些异常而中断执行,导致整个 pipeline job 都失败。为了整个 Job 能继续运行,我们需要处理某些异常。
try catch
当在 Jenkins Pipeline 中使用 try-catch 块时,即使某个阶段失败,后续的阶段也会继续执行。下面是一个示例,演示了一个阶段失败但不影响后续阶段的运行:
pipeline {
agent any
stages {
stage('Example') {
steps {
script {
try {
// 模拟一个可能抛出异常的操作
def result = 10 / 0 // 这里会抛出除以零的异常
echo "Result: