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

Aborting a sh or bat step fires both aborted and failure post conditions

    XMLWordPrintable

Details

    Description

      Consider the following example:

      pipeline {
        agent { 
          label 'linux' 
        }
        stages {
          stage('Successful stage') {
            steps {
              script {
                sh "sleep 15" // intentionally not using sleep 15 step!
              }
            }
          }
        }
        post {
          success {
            echo "Triggered post-success"
          }
          failure {
            echo "Triggered post-failure"
          }
          unstable {
            echo "Triggered post-unstable"
          }
          aborted {
            echo "Triggered post-aborted"
          }
        }
      }
      
      

      Start the build, let it go into "sleep" and abort the build. The result will be:

      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Declarative: Post Actions)
      [Pipeline] echo
      Triggered post-aborted
      [Pipeline] echo
      Triggered post-failure
      [Pipeline] }
      

      The result is having both `post-aborted` and `post-failure` executed. What should have happened was to receive only `post-aborted` step.

      I've also seen in the logs `post-unstable` and `post-failure`, but I am not sure how to provide a way to reproduce this. I'm not sure how that happened but I have seen it a few times on some of our builds. 

       

       

      Attachments

        Issue Links

          Activity

            stodorov Steve Todorov created issue -
            stodorov Steve Todorov made changes -
            Field Original Value New Value
            Description Consider the following example:
            {code:java}
            pipeline {
              agent {
                label 'linux'
              }
              stages {
                stage('Successful stage') {
                  steps {
                    script {
                      sh "sleep 15" // intentionally not using sleep 15 step!
                    }
                  }
                }
              }
              post {
                success {
                  echo "Triggered post-success"
                }
                failure {
                  echo "Triggered post-failure"
                }
                unstable {
                  echo "Triggered post-unstable"
                }
                aborted {
                  echo "Triggered post-aborted"
                }
              }
            }

            {code}
            Start the build, let it go into "sleep" and abort the build. The result will be:
            {code:java}
            [Pipeline] // stage
            [Pipeline] stage
            [Pipeline] { (Declarative: Post Actions)
            [Pipeline] echo
            Triggered post-aborted
            [Pipeline] echo
            Triggered post-failure
            [Pipeline] }
            {code}
            I've also seen in the logs `post-unstable` and `post-failure`, but I am not sure how to provide a way to reproduce this. I'm not sure how that happened but I have seen it a few times on some of our builds. 

             

             
            Consider the following example:
            {code:java}
            pipeline {
              agent {
                label 'linux'
              }
              stages {
                stage('Successful stage') {
                  steps {
                    script {
                      sh "sleep 15" // intentionally not using sleep 15 step!
                    }
                  }
                }
              }
              post {
                success {
                  echo "Triggered post-success"
                }
                failure {
                  echo "Triggered post-failure"
                }
                unstable {
                  echo "Triggered post-unstable"
                }
                aborted {
                  echo "Triggered post-aborted"
                }
              }
            }

            {code}
            Start the build, let it go into "sleep" and abort the build. The result will be:
            {code:java}
            [Pipeline] // stage
            [Pipeline] stage
            [Pipeline] { (Declarative: Post Actions)
            [Pipeline] echo
            Triggered post-aborted
            [Pipeline] echo
            Triggered post-failure
            [Pipeline] }
            {code}
            The result is having both `post-aborted` and `post-failure` executed. What should have happened was to receive only `post-aborted` step.

            I've also seen in the logs `post-unstable` and `post-failure`, but I am not sure how to provide a way to reproduce this. I'm not sure how that happened but I have seen it a few times on some of our builds. 

             

             
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            abayer Andrew Bayer made changes -
            Summary Post stages are incorrectly handled Aborting a sh or bat step fires both aborted and failure post conditions
            abayer Andrew Bayer made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            abayer Andrew Bayer made changes -
            Remote Link This issue links to "PR #262 (Web Link)" [ 20407 ]
            abayer Andrew Bayer made changes -
            Resolution Fixed [ 1 ]
            Status In Review [ 10005 ] Resolved [ 5 ]
            bitwiseman Liam Newman made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

            People

              abayer Andrew Bayer
              stodorov Steve Todorov
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: