我有一系列执行快速检查的阶段。我想把它们都做好,即使失败了。例如:
stage('one') {
node {
sh 'exit 0'
}
}
stage('two') {
node {
sh 'exit 1' // failure
}
}
stage('three') {
node {
sh 'exit 0'
}
}Stage two失败,因此默认情况下不执行stage three。
通常这将是parallel的一项工作,但我希望在舞台视图中显示它们。在下面的模拟中:
two失败,因此three不会运行。two失败并显示为这样,但three仍在运行。真正的Jenkins可能会显示整个版本#6,略带红色,这当然很好。

发布于 2019-07-10 18:50:18
现在这是可能的。下面是一个声明性管道的示例,但是catchError也适用于脚本管道。
pipeline {
agent any
stages {
stage('1') {
steps {
sh 'exit 0'
}
}
stage('2') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh "exit 1"
}
}
}
stage('3') {
steps {
sh 'exit 0'
}
}
}
}在上面的示例中,所有阶段都将执行,管道将成功,但第2阶段将显示为失败:

正如您可能已经猜到的,您可以自由选择buildResult和stageResult,以防您希望它不稳定或其他任何东西。您甚至可以失败构建并继续执行管道。
确保您的Jenkins是最新的,因为这是一个相当新的特性。
发布于 2018-06-15 20:59:20
我也有同样的担心。我解决了这个问题。
第二阶段将以红色显示,并被标记为失败,而其余阶段将继续运行。您可以设置一个标志,并在阶段结束时检查标志并通知整个构建的状态。
node {
def build_ok = true
stage('one') {
sh 'exit 0'
}
try{
stage('two') {
sh 'exit 1' // failure
}
} catch(e) {
build_ok = false
echo e.toString()
}
stage('three') {
sh 'exit 0'
}
....
if(build_ok) {
currentBuild.result = "SUCCESS"
} else {
currentBuild.result = "FAILURE"
}
}发布于 2019-06-24 07:51:48
声明式管道语法
pipeline {
agent any
stages {
stage('one') {
steps {
sh 'exit 0'
}
}
stage('two') {
steps {
sh 'exit 1' // failure
}
}
}
post {
always {
sh 'exit 0'
}
}
}脚本管道语法
node {
def build_ok = true
stage('one') {
sh 'exit 0'
}
try{
stage('two') {
sh 'exit 1' // failure
}
} catch(e) {
build_ok = false
echo e.toString()
}
stage('three') {
sh 'exit 0'
}
if(build_ok) {
currentBuild.result = "SUCCESS"
} else {
currentBuild.result = "FAILURE"
}
}https://stackoverflow.com/questions/40600621
复制相似问题