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

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

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      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.

        Attachments

          Activity

          shubhamsrivastava726 shubham srivastava created issue -
          shubhamsrivastava726 shubham srivastava made changes -
          Field Original Value New Value
          Description 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.
          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.
          shubhamsrivastava726 shubham srivastava made changes -
          Description 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.
          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.
          shubhamsrivastava726 shubham srivastava made changes -
          Description 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.
          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.
          bitwiseman Liam Newman made changes -
          Assignee Andrew Bayer [ abayer ] Liam Newman [ bitwiseman ]

            People

            Assignee:
            bitwiseman Liam Newman
            Reporter:
            shubhamsrivastava726 shubham srivastava
            Votes:
            5 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated: