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

Pipeline stage is started even when currentResult is FAILURE

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Labels:
      None
    • Environment:
      Jenkins 2.222.1, warnings-ng: 8.1, pipeline: 2.6, pipeline-api: 2.40, pipeline-declarative: 1.6.0, workflow-job: 2.38, pipeline-stage-step: 2.38, workflow-step-api: 2.22
    • Similar Issues:

      Description

      There is, from my point of view, unexpected behavior: when some plugin, or some post action, sets the build to the FAILURE, the stage and also build is correctly set to FAILED with the correct color BUT the following stages are executed despite the fact that currentBuild.currentResult is set to FAILURE. I think that the next stages should not be executed when the previous has failed.

      There is existing workaround such as using when expresssion

      when { expression { return currentBuild.result == "SUCCESS" } }
      

      in stage, but I think, that it should be the default behavior.

      Example minimum Jenkinsfile:

      pipeline {
          agent { label 'executor' }
          stages {
              stage("Pylint") {
                  steps {
                      echo "During Build currentResult: ${currentBuild.currentResult}"
                      sh "pylint . > pylint_report.txt"
                  }
                  post {
                      always {
                          //   warnings-ng plugin
                          recordIssues(
                              // Fails the build if errors have been reported during the execution of this step.
                              failOnError: true,
                              // If true, then only successful or unstable builds will be considered as baseline.
                              ignoreFailedBuilds: false,
                              // If the actual number of issues is greater or equal than this threshold then a build is considered as unstable or failed, respectively.
                              qualityGates: [[threshold: 1, type: 'TOTAL', unstable: false]],
                              // Enable recording for failed builds.
                              enabledForFailure: true,
                              tools: [
                                  pyLint(
                                      id: 'pylint-linux',
                                      name: 'Pylint Linux',
                                      pattern: 'pylint_report.txt'
                                  )
                          ])
                      }
                  }
              }
              stage("Push") {
                  // when { expression { return currentBuild.result == "SUCCESS" } }
                  steps {
                      echo "During Build currentResult: ${currentBuild.currentResult}"
                      echo "Why am I executed?"
                  }
              }
          }
      }
      

      Blue Ocean View:

      When there is

        when { expression { return currentBuild.result == "SUCCESS" } }
      

      in the stage, behavior is as expected:

      The log from the job ends with:

      [Pylint Linux] All reported issues will be considered outstanding
      [Pylint Linux] Evaluating quality gates
      [Pylint Linux] -> FAILED - Total (any severity): 1 - Quality QualityGate: 1
      [Pylint Linux] -> Some quality gates have been missed: overall result is FAILED
      [Pylint Linux] Health report is disabled - skipping
      [Pylint Linux] Created analysis result for 1 issues (found 0 new issues, fixed 0 issues)
      [Pylint Linux] Attaching ResultAction with ID 'pylint-linux' to run 'DoSample #2'.
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Deploy)
      [Pipeline] echo
      During Build result: FAILURE
      [Pipeline] echo
      During Build currentResult: FAILURE
      [Pipeline] echo
      Why am I executed?
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: FAILURE
      

      Is this expected behavior?

      When I've played a little more with finding a minimal example, I was able to fail the build only when I've called error().

      pipeline {
          agent { label 'executor' }
          stages {
              stage("pre-build") {
                  steps {
                      echo "currentResult: ${currentBuild.currentResult}"
                  }
                  post {
                      always {
                          script {
                              echo "setting build to failed"
                              currentBuild.result = 'FAILURE'
                              // error('Build has failed')
                          }
                      }
                  }
              }
              stage("deploy") {
                  // when { expression { return currentBuild.currentResult == "SUCCESS" } }
                  steps {
                      echo "currentResult: ${currentBuild.currentResult}"
                      echo "Why am I executed?"
                  }
              }
          }
      }
      

      Maybe it's just warnings-ng should call error() when build should fail?

        Attachments

          Activity

          Hide
          drulli Ulli Hafner added a comment -

          Removing me as assignee (and warnings-ng from components) since the problem seems to be related to pipeline code (and the warnings plugin is just the trigger for the problem).

          Show
          drulli Ulli Hafner added a comment - Removing me as assignee (and warnings-ng from components) since the problem seems to be related to pipeline code (and the warnings plugin is just the trigger for the problem).

            People

            • Assignee:
              Unassigned
              Reporter:
              astaruch Andrej Staruch
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: