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

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

XMLWordPrintable

      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. 

       

       

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

              Created:
              Updated:
              Resolved: