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

`currentBuild.result` is not set to `ABORTED` when the build was aborted

      Right now when the build is aborted using the `pipeline-input-step` plugin in a declarative pipeline, the build result is set to `FAILURE` instead of `ABORTED` in the post section. However, the actual result is properly set to `ABORTED` afterwards. This makes it impossible to do conditional code in the post section.

          [JENKINS-43339] `currentBuild.result` is not set to `ABORTED` when the build was aborted

          Andrew Bayer added a comment -

          Regrettably, not much we can do here - the ABORTED status, in some cases, doesn't get set until the Pipeline finishes executing, so we can't tell from Declarative that we should be treating the build as ABORTED.

          Andrew Bayer added a comment - Regrettably, not much we can do here - the ABORTED status, in some cases, doesn't get set until the Pipeline finishes executing, so we can't tell from Declarative that we should be treating the build as ABORTED .

          abayer, rather than just saying this won't be fixed, perhaps it is better to remove features that provide the illusion that `ABORTED` is a supported state that can be handled in declarative pipelines? Then there will be no confusion

          Phillip Johnston added a comment - abayer , rather than just saying this won't be fixed, perhaps it is better to remove features that provide the illusion that `ABORTED` is a supported state that can be handled in declarative pipelines? Then there will be no confusion

          (I suspect this issue will continue to be reported when someone else tries to handle `aborted` in a `post` block)

          Phillip Johnston added a comment - (I suspect this issue will continue to be reported when someone else tries to handle `aborted` in a `post` block)

          Andrew Bayer added a comment -

          The thing is that ABORTED does work in some contexts, but not others. It's weird.

          Andrew Bayer added a comment - The thing is that ABORTED does work in some contexts, but not others. It's weird.

          Peter Wilcock added a comment - - edited

          abayer I've observed the following:

          When running parallel steps with fastFail set, the fast-failed aborted build will return FAILURE if the act of aborting a step that was still in progress returns an error code. 

          However if other parallel steps have finished successfully, and the last running step fails, this correctly returns ABORTED in the event of failure.

          Some kind of race condition where if a step fails, fastFail aborts all other steps, and the last error code returned is the status seen by the declarative pipeline, but isn't the one respected by the overall build.status? Hopefully that makes sense. 

          Peter Wilcock added a comment - - edited abayer I've observed the following: When running parallel steps with fastFail set, the fast-failed aborted build will return FAILURE if the act of aborting a step that was still in progress  returns an error code.  However if other parallel steps have finished successfully, and the last running step fails, this correctly returns ABORTED in the event of failure. Some kind of race condition where if a step fails, fastFail aborts all other steps, and the last error code returned is the status seen by the declarative pipeline, but isn't the one respected by the overall build.status? Hopefully that makes sense. 

          kutzi added a comment - - edited

          Is there not a reliable way to get from the rawBuild if a build was aborted?
          I cannot image that there's no way - as the builds are eventually - when they are totally finished - always displayed with the right result. 'Only' currentBuild.currentResult is very often giving a different result (FAILURE usually)
          We're using this hack now to get better detection of aborted builds:

          if (currentBuild.rawBuild.getActions(jenkins.model.InterruptedBuildAction.class).isEmpty()) {
             return currentBuild.currentResult
          } else {
            return "ABORTED"
          }
          

          kutzi added a comment - - edited Is there not a reliable way to get from the rawBuild if a build was aborted? I cannot image that there's no way - as the builds are eventually - when they are totally finished - always displayed with the right result. 'Only' currentBuild.currentResult is very often giving a different result (FAILURE usually) We're using this hack now to get better detection of aborted builds: if (currentBuild.rawBuild.getActions(jenkins.model.InterruptedBuildAction.class).isEmpty()) { return currentBuild.currentResult } else { return "ABORTED" }

          Liam Newman added a comment -

          Bulk closing resolved issues.

          Liam Newman added a comment - Bulk closing resolved issues.

          Thanks kutzi – this workaround is indeed very helpful! (Of course one would prefer a proper/clean solution/fix... )

          Reinhold Füreder added a comment - Thanks kutzi – this workaround is indeed very helpful! (Of course one would prefer a proper/clean solution/fix... )

          kutzi added a comment - - edited

          reinholdfuereder according to your comment, you still have experienced this issue in the current release?
          I'm having the workaround in place and therefore not watching it anymore.
          According to Liam's comment this should have been fixed?

          kutzi added a comment - - edited reinholdfuereder  according to your comment, you still have experienced this issue in the current release? I'm having the workaround in place and therefore not watching it anymore. According to Liam's comment this should have been fixed?

          Aleksejs added a comment -

          Jenkins 2.375.1, manually aborted build had `currentBuild.currentResult`= success, sending notification as such. Workaround helped. 

          Aleksejs added a comment - Jenkins 2.375.1, manually aborted build had `currentBuild.currentResult`= success, sending notification as such. Workaround helped. 

            abayer Andrew Bayer
            rochdev Roch Devost
            Votes:
            6 Vote for this issue
            Watchers:
            27 Start watching this issue

              Created:
              Updated:
              Resolved: