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

Not expected behaviour for Post section of DSL pipeline in case of abort

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major

      Issue

      If I abort pipeline during shell step running (probably it can be reproduced with other step types) in Post section currentBuild.result value is FAILURE, failure action runs, but finally build is ABORTED

      There was Issue https://issues.jenkins-ci.org/browse/JENKINS-43339], but seems like it not fully fixed issue at the moment.

      Expected behavior

      In case of abort  currentBuild.result is ABORTED in Post section, and aborted action trigger instead failure

      Steps to reproduce

      1. Install Jenkins 2.60.3. I have done it wich docker
      docker run --name abort-test -p 127.0.0.1:8080:8080 jenkins/jenkins:2.60.3
      2. Install suggested plugins in wizzard
      3. create new pipeline http://localhost:8080/view/all/newJob

      pipeline {
          agent any
          stages {
              stage('sleep dsl'){
                  steps{
                      sleep 15
                  }
              }
              stage('sleep sh'){
                  steps{
                      sh "sleep 15"
                  }
              }
          }
          post {
              always{
                  echo "Build status ${currentBuild.result}"
              }
              changed {
                  echo "changed block"
              }
              success {
                  echo "success block"
              }
              unstable {
                  echo "unstable block"
              }
              failure {
                  echo "failure block"
              }
              aborted {
                  echo "aborted block"
              }
          }
      }

      4. Run it
      4.1 firstly just take it to finish. It is of course success

      [Pipeline] node
      Running on master in /var/jenkins_home/workspace/test
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (sleep dsl)
      [Pipeline] sleep
      Sleeping for 15 sec

      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (sleep sh)

      [Pipeline] sh
      [test] Running shell script
      + sleep 15

      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Declarative: Post Actions)
      [Pipeline] echo
      Build status null
      [Pipeline] echo
      success block
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS

      4.2 Then run again and abort in first stage (push red cross

      [Pipeline] node
      Running on master in /var/jenkins_home/workspace/test
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (sleep dsl)
      [Pipeline] sleep
      Sleeping for 15 sec

      Aborted by Andrii Danyleiko

      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (sleep sh)
      Stage 'sleep sh' skipped due to earlier failure(s)
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Declarative: Post Actions)
      [Pipeline] echo
      Build status ABORTED
      [Pipeline] echo
      changed block
      [Pipeline] echo
      aborted block
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: ABORTED

      It is Aborted as expected

      4.3 Abort in second stage.

      [Pipeline] node
      Running on master in /var/jenkins_home/workspace/test
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (sleep dsl)
      [Pipeline] sleep
      Sleeping for 15 sec

      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (sleep sh)
      [Pipeline] sh

      [test] Running shell script
      + sleep 15

      Aborted by Andrii Danyleiko

      Sending interrupt signal to process
      Terminated
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Declarative: Post Actions)
      [Pipeline] echo
      Build status FAILURE
      [Pipeline] echo
      changed block
      [Pipeline] echo
      failure block
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: script returned exit code 143
      Finished: ABORTED

      why?

      4.4. Pause in second stage (with "Pause/resume"). Wait at least 15s (to be sure that shell finished). Then push red cross and again "Pause/resume" (If you not wait or wait after abort before resume it will be the same as 4.3 case)
      Started by user Andrii Danyleiko
      Replayed #9
      [Pipeline] node
      Running on master in /var/jenkins_home/workspace/test
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (sleep dsl)
      [Pipeline] sleep
      Sleeping for 15 sec

      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (sleep sh)
      [Pipeline] sh

      [test] Running shell script
      + sleep 15

      Pausing

      Aborted by Andrii Danyleiko

      Resuming
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Declarative: Post Actions)
      [Pipeline] echo
      Build status ABORTED
      [Pipeline] echo
      aborted block
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: ABORTED

            abayer Andrew Bayer
            deftez Andrii Danyleiko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: