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

Execution of post stage block is based on pipeline status, not stage result which docs says it should

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Blocker Blocker
    • pipeline
    • None

      The declarative pipeline documentation on "post" says the following: "These condition blocks allow the execution of steps inside each condition depending on the completion status of the Pipeline or stage" 

      Currently, the post execution of a stage seems to refer to the whole pipeline status at that point and not the completion status of the stage as documented.

      Given the following pipeline:

      pipeline {
        agent any
        stages {
          stage('First') {
            steps { echo 'Hello' }
            post { success { echo 'First stage is success' } }
          }
          stage('Second') {
            steps { sh """ echo '<testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>' > test-results.xml """ }
            post {
              always { junit 'test-results.xml' }
              unstable { echo 'Second stage is unstable' }
            }
          }
          stage('Third') {
            steps { echo 'Hello' }
            post {
              success { echo 'Third stage is success' }
              unstable { echo 'Third stage is unstable! really???' }
            }
          }
        }
        post { unstable { echo 'Job is unstable' } }
      }
      
      

      I get the following output:

      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (First)
      [Pipeline] echo
      Hello
      Post stage
      [Pipeline] echo
      First stage is success
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Second)
      [Pipeline] sh
      + echo <testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>
      Post stage
      [Pipeline] junit
      Recording test results
      [Pipeline] echo
      Second stage is unstable
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Third)
      [Pipeline] echo
      Hello
      Post stage
      [Pipeline] echo
      Third stage is unstable! really???
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Declarative: Post Actions)
      [Pipeline] echo
      Job is unstable
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      

      Clearly the third stage post unstable block is executed even though the stage itself is a success.

      This is also contradicted by the blue ocean stage view:

          [JENKINS-57801] Execution of post stage block is based on pipeline status, not stage result which docs says it should

          Daniel Beland created issue -
          Marcus Philip made changes -
          Summary Original: Execution of the wrong post stage block New: Execution post stage block is based on pipeline status, not stage result
          Marcus Philip made changes -
          Summary Original: Execution post stage block is based on pipeline status, not stage result New: Execution of post stage block is based on pipeline status, not stage result
          Marcus Philip made changes -
          Description Original: The declarative pipeline documentation on "post" says the following: "These condition blocks allow the execution of steps inside each condition depending on the completion status of the Pipeline or stage"

           

          Currently, the post execution of a stage seems to refer to the whole pipeline status at that point and not the completion status of the stage as documented.

           

          Given the following pipeline:
          {code:java}
          pipeline {
            agent any
            stages {
              stage('First') {
                steps { echo 'Hello' }
                post { success { echo 'First stage is success' } }
              }
              stage('Second') {
                steps { sh """ echo '<testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>' > test-results.xml """ }
                post {
                  always { junit 'test-results.xml' }
                  unstable { echo 'Second stage is unstable' }
                }
              }
              stage('Third') {
                steps { echo 'Hello' }
                post {
                  success { echo 'Third stage is success' }
                  unstable { echo 'Third stage is unstable! really???' }
                }
              }
            }
            post { unstable { echo 'Job is unstable' } }
          }

          {code}
          I get the following output:
          {noformat}
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (First)
          [Pipeline] echo
          Hello
          Post stage
          [Pipeline] echo
          First stage is success
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Second)
          [Pipeline] sh
          + echo <testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>
          Post stage
          [Pipeline] junit
          Recording test results
          [Pipeline] echo
          Second stage is unstable
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Third)
          [Pipeline] echo
          Hello
          Post stage
          [Pipeline] echo
          Third stage is unstable! really???
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Declarative: Post Actions)
          [Pipeline] echo
          Job is unstable
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {noformat}
          Clearly the third stage post unstable block is executed even though the stage itself is a success.

          This is also contradicted by the blue ocean stage view:

           

          !image-2019-05-31-14-26-08-781.png!

           

           
          New: The declarative pipeline documentation on "post" says the following: "These condition blocks allow the execution of steps inside each condition depending on the completion status of the Pipeline or stage" 

          Currently, the post execution of a stage seems to refer to the whole pipeline status at that point and not the completion status of the stage as documented.

          Given the following pipeline:
          {code:java}
          pipeline {
            agent any
            stages {
              stage('First') {
                steps { echo 'Hello' }
                post { success { echo 'First stage is success' } }
              }
              stage('Second') {
                steps { sh """ echo '<testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>' > test-results.xml """ }
                post {
                  always { junit 'test-results.xml' }
                  unstable { echo 'Second stage is unstable' }
                }
              }
              stage('Third') {
                steps { echo 'Hello' }
                post {
                  success { echo 'Third stage is success' }
                  unstable { echo 'Third stage is unstable! really???' }
                }
              }
            }
            post { unstable { echo 'Job is unstable' } }
          }

          {code}
          I get the following output:
          {noformat}
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (First)
          [Pipeline] echo
          Hello
          Post stage
          [Pipeline] echo
          First stage is success
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Second)
          [Pipeline] sh
          + echo <testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>
          Post stage
          [Pipeline] junit
          Recording test results
          [Pipeline] echo
          Second stage is unstable
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Third)
          [Pipeline] echo
          Hello
          Post stage
          [Pipeline] echo
          Third stage is unstable! really???
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Declarative: Post Actions)
          [Pipeline] echo
          Job is unstable
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {noformat}
          Clearly the third stage post unstable block is executed even though the stage itself is a success.

          This is also contradicted by the blue ocean stage view:

           

          !image-2019-05-31-14-26-08-781.png!

           

           
          Marcus Philip made changes -
          Description Original: The declarative pipeline documentation on "post" says the following: "These condition blocks allow the execution of steps inside each condition depending on the completion status of the Pipeline or stage" 

          Currently, the post execution of a stage seems to refer to the whole pipeline status at that point and not the completion status of the stage as documented.

          Given the following pipeline:
          {code:java}
          pipeline {
            agent any
            stages {
              stage('First') {
                steps { echo 'Hello' }
                post { success { echo 'First stage is success' } }
              }
              stage('Second') {
                steps { sh """ echo '<testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>' > test-results.xml """ }
                post {
                  always { junit 'test-results.xml' }
                  unstable { echo 'Second stage is unstable' }
                }
              }
              stage('Third') {
                steps { echo 'Hello' }
                post {
                  success { echo 'Third stage is success' }
                  unstable { echo 'Third stage is unstable! really???' }
                }
              }
            }
            post { unstable { echo 'Job is unstable' } }
          }

          {code}
          I get the following output:
          {noformat}
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (First)
          [Pipeline] echo
          Hello
          Post stage
          [Pipeline] echo
          First stage is success
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Second)
          [Pipeline] sh
          + echo <testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>
          Post stage
          [Pipeline] junit
          Recording test results
          [Pipeline] echo
          Second stage is unstable
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Third)
          [Pipeline] echo
          Hello
          Post stage
          [Pipeline] echo
          Third stage is unstable! really???
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Declarative: Post Actions)
          [Pipeline] echo
          Job is unstable
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {noformat}
          Clearly the third stage post unstable block is executed even though the stage itself is a success.

          This is also contradicted by the blue ocean stage view:

           

          !image-2019-05-31-14-26-08-781.png!

           

           
          New: The declarative pipeline documentation on "post" says the following: "These condition blocks allow the execution of steps inside each condition depending on the completion status of the Pipeline or stage" 

          Currently, the post execution of a stage seems to refer to the whole pipeline status at that point and not the completion status of the stage as documented.

          Given the following pipeline:
          {code:java}
          pipeline {
            agent any
            stages {
              stage('First') {
                steps { echo 'Hello' }
                post { success { echo 'First stage is success' } }
              }
              stage('Second') {
                steps { sh """ echo '<testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>' > test-results.xml """ }
                post {
                  always { junit 'test-results.xml' }
                  unstable { echo 'Second stage is unstable' }
                }
              }
              stage('Third') {
                steps { echo 'Hello' }
                post {
                  success { echo 'Third stage is success' }
                  unstable { echo 'Third stage is unstable! really???' }
                }
              }
            }
            post { unstable { echo 'Job is unstable' } }
          }

          {code}
          I get the following output:
          {noformat}
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (First)
          [Pipeline] echo
          Hello
          Post stage
          [Pipeline] echo
          First stage is success
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Second)
          [Pipeline] sh
          + echo <testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>
          Post stage
          [Pipeline] junit
          Recording test results
          [Pipeline] echo
          Second stage is unstable
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Third)
          [Pipeline] echo
          Hello
          Post stage
          [Pipeline] echo
          Third stage is unstable! really???
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] stage
          [Pipeline] { (Declarative: Post Actions)
          [Pipeline] echo
          Job is unstable
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {noformat}
          Clearly the third stage post unstable block is executed even though the stage itself is a success.

          This is also contradicted by the blue ocean stage view:

          !image-2019-05-31-14-26-08-781.png!
          Marcus Philip made changes -
          Link New: This issue is duplicated by JENKINS-61405 [ JENKINS-61405 ]
          Marcus Philip made changes -
          Summary Original: Execution of post stage block is based on pipeline status, not stage result New: Execution of post stage block is based on pipeline status, not stage result which docs says it should
          Marcus Philip made changes -
          Link New: This issue is caused by JENKINS-37792 [ JENKINS-37792 ]
          Kalle Niemitalo made changes -
          Link New: This issue is duplicated by JENKINS-68281 [ JENKINS-68281 ]
          Kalle Niemitalo made changes -
          Link New: This issue relates to JENKINS-39203 [ JENKINS-39203 ]
          Brian J Murrell made changes -
          Priority Original: Major [ 3 ] New: Blocker [ 1 ]

            Unassigned Unassigned
            dcendents Daniel Beland
            Votes:
            10 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated: