Jenkins:捕获错误以跳到下一阶段,但仍然显示错误阶段失败
Jenkins: Catch error to skip to next stage, but still show errored stage has failed
我目前正在使用 Jenkins catchError
来捕捉一个阶段是否发生错误,如果是,则跳到下一阶段。
我想要呈现的是,如果某个阶段发现错误,在 Jenkins 中呈现为 Red (Failed) , 即使这个阶段被跳过到下一个。
这是 Jenkins 管道阶段的编码方式,以在脚本失败时捕获错误:
stage('test_run') {
steps {
catchError {
sh """#!/bin/bash -l
***
npm run test:run:reporter
"""
}
}
}
我在 Whosebug 中找到了这个解决方案:
Jenkins: Ignore failure in pipeline build step
此解决方案有效,但在 Jenkins 的 运行 中,失败的阶段是呈现 Green(又名 Success) .
这个Jenkins运行表示失败了:
下一阶段实际上是失败的原因,并在发现错误时被跳过,但是,这个阶段显示绿色(成功)并且更愿意将其呈现为红色(失败):
最终的 post 操作显示为 黄色(不稳定) , 通常它显示为 Green (Success):
感谢您的阅读,感谢您的帮助。
您可以使用
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
Add your commands
}
添加要为构建和暂存结果设置的任何结果。
@DashrathMundkar 谢谢
将 catchError() 与 buildResult 和 stageResult 一起使用,但是我将值设置为 'FAILURE',成功了。
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE', message: 'Test Suite had a failure') { }
我目前正在使用 Jenkins catchError
来捕捉一个阶段是否发生错误,如果是,则跳到下一阶段。
我想要呈现的是,如果某个阶段发现错误,在 Jenkins 中呈现为 Red (Failed) , 即使这个阶段被跳过到下一个。
这是 Jenkins 管道阶段的编码方式,以在脚本失败时捕获错误:
stage('test_run') {
steps {
catchError {
sh """#!/bin/bash -l
***
npm run test:run:reporter
"""
}
}
}
我在 Whosebug 中找到了这个解决方案: Jenkins: Ignore failure in pipeline build step
此解决方案有效,但在 Jenkins 的 运行 中,失败的阶段是呈现 Green(又名 Success) .
这个Jenkins运行表示失败了:
下一阶段实际上是失败的原因,并在发现错误时被跳过,但是,这个阶段显示绿色(成功)并且更愿意将其呈现为红色(失败):
最终的 post 操作显示为 黄色(不稳定) , 通常它显示为 Green (Success):
感谢您的阅读,感谢您的帮助。
您可以使用
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
Add your commands
}
添加要为构建和暂存结果设置的任何结果。
@DashrathMundkar 谢谢
将 catchError() 与 buildResult 和 stageResult 一起使用,但是我将值设置为 'FAILURE',成功了。
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE', message: 'Test Suite had a failure') { }