Jenkins忽略阶段失败,但在后期失败

wz1wpwve  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(364)

我有一个Jenkins工作,在这个工作中,我忽略了失败阶段的失败,并继续进行下一个阶段。我能够通过以下方式完成这个工作:

  1. pipeline {
  2. agent any
  3. stages {
  4. stage('1') {
  5. steps {
  6. sh 'exit 0'
  7. }
  8. }
  9. stage('2') {
  10. steps {
  11. catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
  12. sh "exit 1"
  13. }
  14. }
  15. }
  16. stage('3') {
  17. steps {
  18. sh 'exit 0'
  19. }
  20. }
  21. }
  22. }

然而,在我的post操作中,如果在给定阶段发现任何错误或失败,我希望使整个构建失败。目前,我的所有post操作都是一个清理工作。有没有方法可以收集每个步骤的失败/成功状态,然后在post中,如果发现任何失败,使构建失败?例如:

  1. post {
  2. always {
  3. cleanWs disableDeferredWipeout: true, deleteDirs: true
  4. **<parse for errors and mark the build as a success or failure>**
  5. }
  6. }
  7. }
4szc88ey

4szc88ey1#

您可以将buildResult设置为“UNSTABLE”

  1. catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE')

然后在Post action中检查它:

  1. post {
  2. unstable {
  3. script {
  4. currentBuild.result = 'FAILURE'
  5. }
  6. }

但是我不确定你是否可以在post action中改变构建结果。如果它不起作用,你可以尝试在最后一步检查它:

  1. script {
  2. if(currentBuild.resultIsWorseOrEqualTo('UNSTABLE')) {
  3. currentBuild.result = 'FAILURE'
  4. }
  5. }
展开查看全部

相关问题