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

Declarative Post Stage block not Working as exepected in parallel stages

XMLWordPrintable

      In parallel stages .. when each individual stages have post block . the failure block execution is not working as expected

      Sample pipeline script:

      pipeline {
          agent any
          stages{
              stage("initvar"){
                steps{
                  script{
                    sh " echo initvars"
                  }
                }
              }
              stage('Parallel Stage1'){
                  parallel {
                      stage("Stage1.1"){
                          steps{
                              script{
                                  catchError(message: "stage1.1 failed ", stageResult: 'FAILURE'){
                                  sh """
                                     echo pass
                                  """
                                  }
                              }
                          }
                          post{
                              failure{
                                      echo "from stage 1.1"
                              }
                          }
                      }                stage("Stage1.2"){
                          steps{
                              script{
                                  catchError(message: "stage1.2 failed", stageResult: 'FAILURE'){
                                    sh """
                                      echo fail
                                      exit 1
                                    """
                                  }
                              }
                          }
                          post{
                              failure{
                                    echo "from stage 1.2"
                              }
                          }
                      }
                  }
              }
              
              stage("Parallel Stage 2"){
                  parallel{
                      stage("Stage2.1"){
                          steps{
                              script{
                                 catchError( message: "stage1.2 failed", stageResult: 'FAILURE'){
                                  
                                      sh """
                                          echo "new pass"
                                      """
                                     
                                 }
                              }
                          }
                          post{
                              failure{
                                  script{
                                      echo "from stage 2.1"
                                  }
                              }
                          }
                      }
                      stage("Stage 2.2"){
                          steps{
                              script{
                                 catchError( message: "stage2.2 failed", stageResult: 'FAILURE'){
                                      sh """
                                          exit 1
                                      """
                                 }
                              }
                          }
                          post{
                              failure{
                                  script{
                                      echo "from stage 2.2"
                                  }
                              }
                          }
                      }
                      
                  }
              }
              
          }
          post{
              always{
                  sh "echo always"  
              }
              success{
                  script{
                      sh "echo success"
                  }
              }
              failure{
                  script{
                      sh "echo failure"
                  }
              }
          }
      }
      

      Here post failure block of stage 1.1 and 2.1 should not have been executed

       

      Jenkins version 2.190.2

      Pipeline groovy 2.78

      Pipeline: Basic Steps : 2.18

            Unassigned Unassigned
            krishnams krishnamurthy ms
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: