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

Post steps in parallel parent are executed after previous stage failure

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When a pipeline stage fails, subsequent stages execute their "failure" post steps even if they are skipped. This only occurs for stages which host parallel child stages.

       

      Example:

      pipeline {
        agent none
      
        stages {
          stage('One') {
            agent any
      
            steps {
              error('fail')
            }
      
            post {
              failure {
                echo 'One'
              }
          }
      
          stage('Two') {
            agent any
      
            steps {
              echo "Shouldn't run"
            }
      
            post {
              failure {
                echo 'Two'
              }
            }
          }
      
          stage('Three') {
            parallel {
              stage('Child 1') {
                agent any
                steps { echo 'Child 1' }
              }
              stage('Child 2') {
                agent any
                steps { echo 'Chlid 2' }
              }
            }
      
            post {
              failure {
                echo 'Three'
              }
            }
          }
        }
      }

      This will echo:

      One
      Three
      

        Attachments

          Activity

          tad Tad Fisher created issue -
          tad Tad Fisher made changes -
          Field Original Value New Value
          Description When a pipeline stage fails, subsequent stages execute their "failure" post steps even if they are skipped. This only occurs for stages which host parallel child stages.

           

          Example:
          {code:java}
          pipeline {
            agent none

            stages {
              stage('One') {
                agent any

                steps {
                  error('fail')
                }

                post {
                  failure {
                    echo 'One'
                  }
              }

              stage('Two') {
                agent any

                steps {
                  echo "Shouldn't run"
                }

                post {
                  failure {
                    echo 'Two'
                  }
                }
              }

              stage('Three') {
                parallel {
                  stage('Child 1') {
                    agent any
                    steps { echo 'Child 1' }
                  }
                  stage('Child 2') {
                    agent any
                    steps { echo 'Chlid 2' }
                  }
                }

                post {
                  failure {
                    echo 'Three'
                  }
                }
              }
            }
          }{code}
          When a pipeline stage fails, subsequent stages execute their "failure" post steps even if they are skipped. This only occurs for stages which host parallel child stages.

           

          Example:
          {code:java}
          pipeline {
            agent none

            stages {
              stage('One') {
                agent any

                steps {
                  error('fail')
                }

                post {
                  failure {
                    echo 'One'
                  }
              }

              stage('Two') {
                agent any

                steps {
                  echo "Shouldn't run"
                }

                post {
                  failure {
                    echo 'Two'
                  }
                }
              }

              stage('Three') {
                parallel {
                  stage('Child 1') {
                    agent any
                    steps { echo 'Child 1' }
                  }
                  stage('Child 2') {
                    agent any
                    steps { echo 'Chlid 2' }
                  }
                }

                post {
                  failure {
                    echo 'Three'
                  }
                }
              }
            }
          }{code}

          This will echo:


          {noformat}
          One
          Three
          {noformat}
          Hide
          abayer Andrew Bayer added a comment -

          Merged, will be released in 1.2.5.

          Show
          abayer Andrew Bayer added a comment - Merged, will be released in 1.2.5.
          abayer Andrew Bayer made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Tad Fisher
          Path:
          pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/PostStageTest.java
          pipeline-model-definition/src/test/resources/postStage/parallelParentPostFailure.groovy
          http://jenkins-ci.org/commit/pipeline-model-definition-plugin/7b517d774dcaf7d00452e2fdab861f04d352d0ac
          Log:
          Reproduce JENKINS-47928 in test

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Tad Fisher Path: pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/PostStageTest.java pipeline-model-definition/src/test/resources/postStage/parallelParentPostFailure.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/7b517d774dcaf7d00452e2fdab861f04d352d0ac Log: Reproduce JENKINS-47928 in test
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Tad Fisher
          Path:
          pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
          http://jenkins-ci.org/commit/pipeline-model-definition-plugin/9089754a207584dcb477b8f376d003ba7e98badb
          Log:
          [FIXED JENKINS-47928] Skip parallel stage post for previous errors

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Tad Fisher Path: pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/9089754a207584dcb477b8f376d003ba7e98badb Log: [FIXED JENKINS-47928] Skip parallel stage post for previous errors
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Andrew Bayer
          Path:
          pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
          pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/PostStageTest.java
          pipeline-model-definition/src/test/resources/postStage/postAfterParallel.groovy
          http://jenkins-ci.org/commit/pipeline-model-definition-plugin/8e18c3506e63e9ee06d8f5f69c26649d6b8ae3f6
          Log:
          [FIXED JENKINS-48266] Skip post for skipped parallel stages

          The JENKINS-47928 fix was actually not right - it disabled calling
          post entirely for parallel parent stages if they weren't the source of
          an error themselves. That means they weren't called at all if there
          was no failure!

          The proper fix is to track whether a parallel parent stage has been
          skipped, and if so, skip post execution as well. Which is what's done
          here. Tada.

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/PostStageTest.java pipeline-model-definition/src/test/resources/postStage/postAfterParallel.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/8e18c3506e63e9ee06d8f5f69c26649d6b8ae3f6 Log: [FIXED JENKINS-48266] Skip post for skipped parallel stages The JENKINS-47928 fix was actually not right - it disabled calling post entirely for parallel parent stages if they weren't the source of an error themselves. That means they weren't called at all if there was no failure! The proper fix is to track whether a parallel parent stage has been skipped, and if so, skip post execution as well. Which is what's done here. Tada.

            People

            • Assignee:
              abayer Andrew Bayer
              Reporter:
              tad Tad Fisher
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: