我正在<iframe width="420" height="345" src="https://www.youtube.com/embed/tgbNymZ7vqY?autoplay=1">
</iframe>
内的大多数阶段中实现一个try catch
块,以在当前阶段失败时跳过以下所有阶段,但是,我的阶段之一正在返回错误,但仍然继续执行下一个阶段。
我尝试使用jenkins pipeline
(如果else子句检查阶段结果,但无济于事)。
sh 'exit 1', currentStage.result = 'FAILED'
我希望在我的pipeline {
agent none
stages {
stage ('one') {
steps {
echo 'Next stage should be skipped if this stage fails'
script {
try {
sh '''#!/bin/bash -l
source ~/.nvm/nvm.sh
nvm use node
node somefile.js'''
}
catch (e) {
currentBuild.result = 'FAILURE';
throw e
}
}
}
}
stage ('two') {
steps {
echo 'This stage should be skipped if prior stage throws an erorr'
}
}
}
}
抛出错误时跳过第二阶段。
答案 0 :(得分:1)
您可以使用Jenkins提供的when-clause
(Source)。
stage ('two') {
// Skip this stage if pipeline has already failed
when { not { equals expected: 'FAILURE', actual: currentBuild.result } }
steps {
echo 'This stage should be skipped if prior stage throws an erorr'
}
}