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

    • Similar Issues:

      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

            Hide
            abayer Andrew Bayer added a comment -

            So what's happening exactly? You're aborting a build and post conditions besides aborted are firing?

            Show
            abayer Andrew Bayer added a comment - So what's happening exactly? You're aborting a build and post conditions besides aborted are firing?
            Hide
            stodorov Steve Todorov added a comment -

            Sorry for the delayed reply. The issue is that both the post-abort and post-failure steps are triggered when you abort a build. What should have happened was to receive only post-abort when you hit the Abort button.

            In our case we are trying to execute specific steps only for post-abort and other specific steps only for post-failure, however we end up having both steps for post-abort and post-failure executed which is messing things up. 

             

             

            Show
            stodorov Steve Todorov added a comment - Sorry for the delayed reply. The issue is that both the  post-abort and  post-failure steps are triggered when you abort a build. What should have happened was to receive only post-abort  when you hit the Abort button. In our case we are trying to execute specific steps only for post-abort  and other specific steps only for  post-failure , however we end up having both steps for post-abort and post-failure executed which is messing things up.     
            Hide
            abayer Andrew Bayer added a comment -

            Ok, reproduced it - the sh 'sleep 15' is the reason none of the existing tests caught this. It seems to only be sh or bat getting aborted that results in both failure and aborted firing.

            Show
            abayer Andrew Bayer added a comment - Ok, reproduced it - the sh 'sleep 15' is the reason none of the existing tests caught this. It seems to only be sh or bat getting aborted that results in both failure and aborted firing.
            Hide
            abayer Andrew Bayer added a comment -
            Show
            abayer Andrew Bayer added a comment - And I have a fix (I believe) - https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/262 .
            Hide
            stodorov Steve Todorov added a comment -

            Thanks for your quick fix! Let me know if there is going to be a snapshot release which I could test. 

            Show
            stodorov Steve Todorov added a comment - Thanks for your quick fix! Let me know if there is going to be a snapshot release which I could test. 
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Failure.groovy
            pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BuildConditionResponderTest.java
            http://jenkins-ci.org/commit/pipeline-model-definition-plugin/70d2af8039aa06db05fb0bb1dcc2d370940387ac
            Log:
            [FIXED JENKINS-50652] Don't fire post failure for aborted durable task

            It appears that an aborted durable task like sh results in
            `CpsFlowExecution#result` being `ABORTED`, but `WorkflowRun#result`
            being `FAILURE`, until the whole build actually finishes and the run
            gets updated accordingly. So the `failure` `post` condition shouldn't
            fire if `CpsFlowExecution#result` is `ABORTED`.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Failure.groovy pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BuildConditionResponderTest.java http://jenkins-ci.org/commit/pipeline-model-definition-plugin/70d2af8039aa06db05fb0bb1dcc2d370940387ac Log: [FIXED JENKINS-50652] Don't fire post failure for aborted durable task It appears that an aborted durable task like sh results in `CpsFlowExecution#result` being `ABORTED`, but `WorkflowRun#result` being `FAILURE`, until the whole build actually finishes and the run gets updated accordingly. So the `failure` `post` condition shouldn't fire if `CpsFlowExecution#result` is `ABORTED`.
            Hide
            abayer Andrew Bayer added a comment -

            Will be released in Declarative 1.2.9 later today.

            Show
            abayer Andrew Bayer added a comment - Will be released in Declarative 1.2.9 later today.

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                stodorov Steve Todorov
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: