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

Declarative Pipeline shows SUCCESS even though job FAILED

    • pipeline-model-definition 1.3.7

      Pipelines are "failing" with SUCCESS status. 

      This pipeline, taken from JENKINS-46325 illustrates this issue successfully:

      pipeline {
          agent any
          stages {
              stage ('Init') {
                  steps {
                      echo "Init result: ${currentBuild.result}"
                      echo "Init currentResult: ${currentBuild.currentResult}"
                  }
                  post {
                      always {
                          echo "Post-Init result: ${currentBuild.result}"
                          echo "Post-Init currentResult: ${currentBuild.currentResult}"
                      }
                  }
              }
              stage ('Build') {
                  steps {
                      echo "During Build result: ${currentBuild.result}"
                      echo "During Build currentResult: ${currentBuild.currentResult}"
                      sh 'exit 1'
                  }
                  post {
                      always {
                          echo "Post-Build result: ${currentBuild.result}"
                          echo "Post-Build currentResult: ${currentBuild.currentResult}"
                      }
                  }
              }
          }
          post {
              always {
                  echo "Pipeline result: ${currentBuild.result}"
                  echo "Pipeline currentResult: ${currentBuild.currentResult}"
              }
          }
      }
      

       

      My results are (trimmed down):

      Running on build-096575a3-e6af-4fff-9ca1-84cc46ba4b86-f9b8d29c in /var/vcap/data/jenkins-slave/workspace/test-job
      Init result: null
      Init currentResult: SUCCESS
      Post stage
      Post-Init result: null
      Post-Init currentResult: SUCCESS
      During Build result: null
      During Build currentResult: SUCCESS
      [Pipeline] sh
      + exit 1
      Post stage
      Post-Build result: null
      Post-Build currentResult: SUCCESS
      Pipeline result: null
      Pipeline currentResult: SUCCESS
      ERROR: script returned exit code 1
      Finished: FAILURE
      

       

          [JENKINS-56402] Declarative Pipeline shows SUCCESS even though job FAILED

          Philip Zozobrado created issue -
          Philip Zozobrado made changes -
          Description Original: Pipelines are "failing" with SUCCESS status. 

          This pipeline, taken from JENKINS-46325 illustrates this issues successfully:
          {code}
          pipeline {
              agent any
              stages {
                  stage ('Init') {
                      steps {
                          echo "Init result: ${currentBuild.result}"
                          echo "Init currentResult: ${currentBuild.currentResult}"
                      }
                      post {
                          always {
                              echo "Post-Init result: ${currentBuild.result}"
                              echo "Post-Init currentResult: ${currentBuild.currentResult}"
                          }
                      }
                  }
                  stage ('Build') {
                      steps {
                          echo "During Build result: ${currentBuild.result}"
                          echo "During Build currentResult: ${currentBuild.currentResult}"
                          sh 'exit 1'
                      }
                      post {
                          always {
                              echo "Post-Build result: ${currentBuild.result}"
                              echo "Post-Build currentResult: ${currentBuild.currentResult}"
                          }
                      }
                  }
              }
              post {
                  always {
                      echo "Pipeline result: ${currentBuild.result}"
                      echo "Pipeline currentResult: ${currentBuild.currentResult}"
                  }
              }
          }
          {code}
           

          My results are (trimmed down):
          {noformat}
          Running on build-096575a3-e6af-4fff-9ca1-84cc46ba4b86-f9b8d29c in /var/vcap/data/jenkins-slave/workspace/test-job
          Init result: null
          Init currentResult: SUCCESS
          Post stage
          Post-Init result: null
          Post-Init currentResult: SUCCESS
          During Build result: null
          During Build currentResult: SUCCESS
          [Pipeline] sh
          + exit 1
          Post stage
          Post-Build result: null
          Post-Build currentResult: SUCCESS
          Pipeline result: null
          Pipeline currentResult: SUCCESS
          ERROR: script returned exit code 1
          Finished: FAILURE
          {noformat}
           
          New: Pipelines are "failing" with SUCCESS status. 

          This pipeline, taken from JENKINS-46325 illustrates this issue successfully:
          {code:java}
          pipeline {
              agent any
              stages {
                  stage ('Init') {
                      steps {
                          echo "Init result: ${currentBuild.result}"
                          echo "Init currentResult: ${currentBuild.currentResult}"
                      }
                      post {
                          always {
                              echo "Post-Init result: ${currentBuild.result}"
                              echo "Post-Init currentResult: ${currentBuild.currentResult}"
                          }
                      }
                  }
                  stage ('Build') {
                      steps {
                          echo "During Build result: ${currentBuild.result}"
                          echo "During Build currentResult: ${currentBuild.currentResult}"
                          sh 'exit 1'
                      }
                      post {
                          always {
                              echo "Post-Build result: ${currentBuild.result}"
                              echo "Post-Build currentResult: ${currentBuild.currentResult}"
                          }
                      }
                  }
              }
              post {
                  always {
                      echo "Pipeline result: ${currentBuild.result}"
                      echo "Pipeline currentResult: ${currentBuild.currentResult}"
                  }
              }
          }
          {code}
           

          My results are (trimmed down):
          {noformat}
          Running on build-096575a3-e6af-4fff-9ca1-84cc46ba4b86-f9b8d29c in /var/vcap/data/jenkins-slave/workspace/test-job
          Init result: null
          Init currentResult: SUCCESS
          Post stage
          Post-Init result: null
          Post-Init currentResult: SUCCESS
          During Build result: null
          During Build currentResult: SUCCESS
          [Pipeline] sh
          + exit 1
          Post stage
          Post-Build result: null
          Post-Build currentResult: SUCCESS
          Pipeline result: null
          Pipeline currentResult: SUCCESS
          ERROR: script returned exit code 1
          Finished: FAILURE
          {noformat}
           

          Lakshya Kapoor added a comment - - edited

          I'm experiencing the same. currentBuild.currentResult for all failed and aborted builds returns "SUCCESS". Same when using $BUILD_STATUS through the emailext plugin.

          Using Jenkins version 2.150.3 and Pipeline 2.6. All pipeline related plugins are at the latest version as well.

          Lakshya Kapoor added a comment - - edited I'm experiencing the same. currentBuild.currentResult  for all failed and aborted builds returns "SUCCESS". Same when using $BUILD_STATUS through the emailext plugin. Using Jenkins version 2.150.3 and Pipeline 2.6. All pipeline related plugins are at the latest version as well.
          Philip Zozobrado made changes -
          Environment Original: Jenkins 2.150.3, using a slave build executioner New: Jenkins 2.150.3, Pipeline 2.6, using a slave build executioner

          I investigated this issue and looks like it introduced by the Pipeline: Declarative plugin v1.3.5. The offending commit seems to be https://github.com/jenkinsci/pipeline-model-definition-plugin/commit/39c7ed1e153bc3ae10a8aaf77ccc3bc7da2dc93a.

          Downgrading to v1.3.4.1 is the workaround for now.

          Lakshya Kapoor added a comment - I investigated this issue and looks like it introduced by the  Pipeline: Declarative  plugin v1.3.5. The offending commit seems to be  https://github.com/jenkinsci/pipeline-model-definition-plugin/commit/39c7ed1e153bc3ae10a8aaf77ccc3bc7da2dc93a . Downgrading to v1.3.4.1 is the workaround for now.

          ^^ I can confirm, symptoms arise upgrading to 1.3.5. I updated an older Jenkins to 1.3.5 and it resulted in the same symptoms. Downgrading back to 1.3.4.1 resolved it.

          Philip Zozobrado added a comment - ^^ I can confirm, symptoms arise upgrading to 1.3.5. I updated an older Jenkins to 1.3.5 and it resulted in the same symptoms. Downgrading back to 1.3.4.1 resolved it.

          Devin Nusbaum added a comment - - edited

          kapoorlakshya Yes, this is caused by PR 313, which was the fix for JENKINS-55459. In general, you cannot use currentBuild.result to accurately determine the current state of the build, because currentBuild.result does not take into account any in-flight exceptions that are propagating throughout the execution and will cause it to result in failure at the top-level. Post conditions in Declarative do account for these in-flight exceptions and should be triggered appropriately. Getting and/or setting the build result is somewhat messy in Scripted Pipeline as well and does not always do what you want because there is no step-level build result, only an overall build result. The changes made in PR 313 made Declarative match the behavior of Scripted.

          What is your actual use case? Can you use post conditions without actually inspecting the build result? Perhaps we could provide some other kind of API visible to scripts to expose the ephemeral result that will be used when deciding what POST steps to run, but if you are setting the build result intentionally to try and change the flow of execution then I am not sure what we could do to fix that use case. CC abayer

          Devin Nusbaum added a comment - - edited kapoorlakshya Yes, this is caused by PR 313 , which was the fix for JENKINS-55459 . In general, you cannot use currentBuild.result to accurately determine the current state of the build, because currentBuild.result does not take into account any in-flight exceptions that are propagating throughout the execution and will cause it to result in failure at the top-level. Post conditions in Declarative do account for these in-flight exceptions and should be triggered appropriately. Getting and/or setting the build result is somewhat messy in Scripted Pipeline as well and does not always do what you want because there is no step-level build result, only an overall build result. The changes made in PR 313 made Declarative match the behavior of Scripted. What is your actual use case? Can you use post conditions without actually inspecting the build result? Perhaps we could provide some other kind of API visible to scripts to expose the ephemeral result that will be used when deciding what POST steps to run, but if you are setting the build result intentionally to try and change the flow of execution then I am not sure what we could do to fix that use case. CC abayer
          Devin Nusbaum made changes -
          Component/s New: pipeline-model-definition-plugin [ 21706 ]
          Component/s Original: pipeline [ 21692 ]
          Devin Nusbaum made changes -
          Link New: This issue relates to JENKINS-55459 [ JENKINS-55459 ]

          Philip Zozobrado added a comment - - edited

          dnusbaum Does all what you said also apply to currentBuild.currentResult ? It's also showing incorrectly on failed stages.

          Can you use POST conditions without actually inspecting the build result?

          I'd like to answer your question with another question: How do we get a build status when inspecting currentBuild if result and currentResult are both incorrect on a build failure?

          Wouldn't this also make resultIsBetterOrEqualTo and resultIsWorseOrEqualTo now moot since we can no longer rely on any build status checks?

          Philip Zozobrado added a comment - - edited dnusbaum Does all what you said also apply to currentBuild.currentResult ? It's also showing incorrectly on failed stages. Can you use POST conditions without actually inspecting the build result? I'd like to answer your question with another question: How do we get a build status when inspecting currentBuild if result and currentResult are both incorrect on a build failure? Wouldn't this also make resultIsBetterOrEqualTo and resultIsWorseOrEqualTo now moot since we can no longer rely on any build status checks?

            Unassigned Unassigned
            pzozobrado Philip Zozobrado
            Votes:
            23 Vote for this issue
            Watchers:
            42 Start watching this issue

              Created:
              Updated: