Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-61209

Issue in catchError functionality, Post feature is not working as expected

      i have three stages 

      pipeline {
          agent {
              node {
                  label "myNode"
              }
          }
          stages {
              stage("Stage 1") {
                  steps {
                      catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                          bat 'exit 1'
                      }
                  }
                  post {
                      success {
                          println "stage 1 Message from post: ........success........."
                      }
                      unstable {
                          println "stage 1 Message from post: ........unstable........"
                      }
                      failure {
                          println "Stage 1 Message from post: ........failure........."
                      }
                  }
              }
              stage("Stage 2") {
                  steps {
                      catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                          bat "exit 0"
                      }
                  }
                  post {
                      success {
                          println "stage 2 Message from post: ........success........."
                      }
                      unstable {
                          println "stage 2 Message from post: ........unstable........"
                      }
                      failure {
                          println "stage 2 Message from post: ........failure........."
                      }
                  }
              }
       stage("Stage 3") {
                  steps {
                      catchError(buildResult: 'FAILURE', catchInterruptions: false, message: 'stage failed', stageResult: 'UNSTABLE') {
                          bat "exit 1"
                      }
                  }
                  post {
                      success {
                          println "stage 3 Message from post: ........success........."
                      }
                      unstable {
                          println "stage 3 Message from post: ........unstable........"
                      }
                      failure {
                          println "stage 3 Message from post: ........failure........."
                      }
                  }
              }
          }
      }
      

      As per the documentation, my output should be

      Stage 1 Message from post: ........failure.........
      stage 2 Message from post: ........success.........
      stage 3 Message from post: ........unstable.........
      

      But actually the output is

      Stage 1 Message from post: ........failure.........
      stage 2 Message from post: ........unstable........
      stage 3 Message from post: ........failure........
      

      After the analysis i found out that the post feature in stage block are working according to the buildResult rather than stage result.
      Post feature is working fine only for the first stage which got failed in the pipeline not for the subsequent stage.

          [JENKINS-61209] Issue in catchError functionality, Post feature is not working as expected

          shubham srivastava created issue -
          shubham srivastava made changes -
          Description Original: i have two stages 
          {noformat}
          pipeline {
              agent {
                  node {
                      label "myNode"
                  }
              }
              stages {
                  stage("Stage 1") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat 'exit 1'
                          }
                      }
                      post {
                          success {
                              println "stage 1 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 1 Message from post: ........unstable........"
                          }
                          failure {
                              println "Stage 1 Message from post: ........failure........."
                          }
                      }
                  }
                  stage("Stage 2") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 2 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 2 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 2 Message from post: ........failure........."
                          }
                      }
                  }
              }
          }
          {noformat}
          As per the documentation, my output should be
          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........success.........
          {noformat}
          But actually the output is

          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........unstable........
          {noformat}
          After the analysis i found out that the post feature in stage block are working according to the buildResult rather than stage result.
          New: i have three stages 
          {noformat}
          pipeline {
              agent {
                  node {
                      label "myNode"
                  }
              }
              stages {
                  stage("Stage 1") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat 'exit 1'
                          }
                      }
                      post {
                          success {
                              println "stage 1 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 1 Message from post: ........unstable........"
                          }
                          failure {
                              println "Stage 1 Message from post: ........failure........."
                          }
                      }
                  }
                  stage("Stage 2") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 2 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 2 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 2 Message from post: ........failure........."
                          }
                      }
                  }
           stage("Stage 3") {
                      steps {
                          catchError(buildResult: 'FAILURE', catchInterruptions: false, message: 'stage failed', stageResult: 'UNSTABLE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 3 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 3 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 3 Message from post: ........failure........."
                          }
                      }
                  }
              }
          }
          {noformat}
          As per the documentation, my output should be
          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........success.........
          stage 3 Message from post: ........unstable.........
          {noformat}
          But actually the output is

          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........unstable........
          stage 3 Message from post: ........failure........
          {noformat}
          After the analysis i found out that the post feature in stage block are working according to the buildResult rather than stage result.
          Post feature is working fine only for the first stage which got failed in the pipeline not for the subsequent stage.
          shubham srivastava made changes -
          Description Original: i have three stages 
          {noformat}
          pipeline {
              agent {
                  node {
                      label "myNode"
                  }
              }
              stages {
                  stage("Stage 1") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat 'exit 1'
                          }
                      }
                      post {
                          success {
                              println "stage 1 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 1 Message from post: ........unstable........"
                          }
                          failure {
                              println "Stage 1 Message from post: ........failure........."
                          }
                      }
                  }
                  stage("Stage 2") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 2 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 2 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 2 Message from post: ........failure........."
                          }
                      }
                  }
           stage("Stage 3") {
                      steps {
                          catchError(buildResult: 'FAILURE', catchInterruptions: false, message: 'stage failed', stageResult: 'UNSTABLE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 3 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 3 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 3 Message from post: ........failure........."
                          }
                      }
                  }
              }
          }
          {noformat}
          As per the documentation, my output should be
          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........success.........
          stage 3 Message from post: ........unstable.........
          {noformat}
          But actually the output is

          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........unstable........
          stage 3 Message from post: ........failure........
          {noformat}
          After the analysis i found out that the post feature in stage block are working according to the buildResult rather than stage result.
          Post feature is working fine only for the first stage which got failed in the pipeline not for the subsequent stage.
          New: i have three stages 
          {noformat}
          pipeline {
              agent {
                  node {
                      label "myNode"
                  }
              }
              stages {
                  stage("Stage 1") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat 'exit 1'
                          }
                      }
                      post {
                          success {
                              println "stage 1 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 1 Message from post: ........unstable........"
                          }
                          failure {
                              println "Stage 1 Message from post: ........failure........."
                          }
                      }
                  }
                  stage("Stage 2") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 2 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 2 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 2 Message from post: ........failure........."
                          }
                      }
                  }
           stage("Stage 3") {
                      steps {
                          catchError(buildResult: 'FAILURE', catchInterruptions: false, message: 'stage failed', stageResult: 'UNSTABLE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 3 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 3 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 3 Message from post: ........failure........."
                          }
                      }
                  }
              }
          }
          {noformat}
          As per the documentation, my output should be
          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........success.........
          stage 3 Message from post: ........success.........
          {noformat}
          But actually the output is

          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........unstable........
          stage 3 Message from post: ........failure........
          {noformat}
          After the analysis i found out that the post feature in stage block are working according to the buildResult rather than stage result.
          Post feature is working fine only for the first stage which got failed in the pipeline not for the subsequent stage.
          shubham srivastava made changes -
          Description Original: i have three stages 
          {noformat}
          pipeline {
              agent {
                  node {
                      label "myNode"
                  }
              }
              stages {
                  stage("Stage 1") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat 'exit 1'
                          }
                      }
                      post {
                          success {
                              println "stage 1 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 1 Message from post: ........unstable........"
                          }
                          failure {
                              println "Stage 1 Message from post: ........failure........."
                          }
                      }
                  }
                  stage("Stage 2") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 2 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 2 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 2 Message from post: ........failure........."
                          }
                      }
                  }
           stage("Stage 3") {
                      steps {
                          catchError(buildResult: 'FAILURE', catchInterruptions: false, message: 'stage failed', stageResult: 'UNSTABLE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 3 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 3 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 3 Message from post: ........failure........."
                          }
                      }
                  }
              }
          }
          {noformat}
          As per the documentation, my output should be
          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........success.........
          stage 3 Message from post: ........success.........
          {noformat}
          But actually the output is

          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........unstable........
          stage 3 Message from post: ........failure........
          {noformat}
          After the analysis i found out that the post feature in stage block are working according to the buildResult rather than stage result.
          Post feature is working fine only for the first stage which got failed in the pipeline not for the subsequent stage.
          New: i have three stages 
          {noformat}
          pipeline {
              agent {
                  node {
                      label "myNode"
                  }
              }
              stages {
                  stage("Stage 1") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat 'exit 1'
                          }
                      }
                      post {
                          success {
                              println "stage 1 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 1 Message from post: ........unstable........"
                          }
                          failure {
                              println "Stage 1 Message from post: ........failure........."
                          }
                      }
                  }
                  stage("Stage 2") {
                      steps {
                          catchError(buildResult: 'UNSTABLE', catchInterruptions: false, message: 'stage failed', stageResult: 'FAILURE') {
                              bat "exit 0"
                          }
                      }
                      post {
                          success {
                              println "stage 2 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 2 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 2 Message from post: ........failure........."
                          }
                      }
                  }
           stage("Stage 3") {
                      steps {
                          catchError(buildResult: 'FAILURE', catchInterruptions: false, message: 'stage failed', stageResult: 'UNSTABLE') {
                              bat "exit 1"
                          }
                      }
                      post {
                          success {
                              println "stage 3 Message from post: ........success........."
                          }
                          unstable {
                              println "stage 3 Message from post: ........unstable........"
                          }
                          failure {
                              println "stage 3 Message from post: ........failure........."
                          }
                      }
                  }
              }
          }
          {noformat}
          As per the documentation, my output should be
          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........success.........
          stage 3 Message from post: ........unstable.........
          {noformat}
          But actually the output is

          {noformat}
          Stage 1 Message from post: ........failure.........
          stage 2 Message from post: ........unstable........
          stage 3 Message from post: ........failure........
          {noformat}
          After the analysis i found out that the post feature in stage block are working according to the buildResult rather than stage result.
          Post feature is working fine only for the first stage which got failed in the pipeline not for the subsequent stage.

          shubham srivastava added a comment - Above issue is related to this bugfix https://issues.jenkins-ci.org/browse/JENKINS-57826 . There is also an insufficient test case https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/pipeline-model-definition/src/test/resources/postStage/localAll.groovy in the code.
          Liam Newman made changes -
          Assignee Original: Andrew Bayer [ abayer ] New: Liam Newman [ bitwiseman ]

          Liam Newman added a comment -

          Hey, this is a great bug report. Thank you for the analysis.
          Would you be interested in submitting a PR to fix this? It seems like you're already a ways along in understanding it.

          Liam Newman added a comment - Hey, this is a great bug report. Thank you for the analysis. Would you be interested in submitting a PR to fix this? It seems like you're already a ways along in understanding it.

          Hi Liam, it will take sometime for me to fix this issue and create a PR for this.
          Thanks for your response.

          shubham srivastava added a comment - Hi Liam, it will take sometime for me to fix this issue and create a PR for this. Thanks for your response.

          Hi shubhamsrivastava726 ! Any update to share we us ?

          Jérémy Chauvet added a comment - Hi shubhamsrivastava726 ! Any update to share we us ?

          Oleg added a comment -

          Hi, are there any updates or plans to fix related to this bug?

          Oleg added a comment - Hi, are there any updates or plans to fix related to this bug?

            bitwiseman Liam Newman
            shubhamsrivastava726 shubham srivastava
            Votes:
            7 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: