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

Unstable build from junit not picked up in currentBuild.result

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Some time back, declarative pipelines were marking a stage as unstable, and I was able to have something like:

      pipeline {
        stage {
          steps {
            sh 'runuittests'
          }
          post {
            always {
              junit 'junit.xml'
            }
          }
        }
        stage {
          when {
            expression {
              currentBuild.resultIsBetterOrEqualTo('SUCCESS')
            }
          }
          steps {
            // Only runs when tests are stable
          }
        }
      }

      However, this stopped working at some point in the recent past.  

       

      currentBuild.result does not seem to be populated when junit marks the build unstable.

       

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            PR up for junit at https://github.com/jenkinsci/junit-plugin/pull/91 to switch to setting the Run result, getting currentBuild.result and friends back to behaving like expected.

            Show
            abayer Andrew Bayer added a comment - PR up for junit at https://github.com/jenkinsci/junit-plugin/pull/91 to switch to setting the Run result, getting currentBuild.result and friends back to behaving like expected.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            src/main/java/hudson/tasks/junit/pipeline/JUnitResultsStepExecution.java
            src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java
            http://jenkins-ci.org/commit/junit-plugin/acd8f4843602a4629344f4cb404cec2dfb7a54d2
            Log:
            [FIXED JENKINS-48178] Set run result rather than context result

            This fixes currentBuild.result to be UNSTABLE after test failures are
            encountered. We'll want to revisit this in the future once we have
            more granular stage/step status, but going with
            getContext().setResult(...) was, in retrospect, premature optimization.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: src/main/java/hudson/tasks/junit/pipeline/JUnitResultsStepExecution.java src/test/java/hudson/tasks/junit/pipeline/JUnitResultsStepTest.java http://jenkins-ci.org/commit/junit-plugin/acd8f4843602a4629344f4cb404cec2dfb7a54d2 Log: [FIXED JENKINS-48178] Set run result rather than context result This fixes currentBuild.result to be UNSTABLE after test failures are encountered. We'll want to revisit this in the future once we have more granular stage/step status, but going with getContext().setResult(...) was, in retrospect, premature optimization.
            Hide
            abayer Andrew Bayer added a comment -

            Releasing as 1.23 as we speak.

            Show
            abayer Andrew Bayer added a comment - Releasing as 1.23 as we speak.
            Hide
            iko IKO BH added a comment - - edited

            Andrew Bayer

            I use JUnit 1.24 and still failed tests captured by JUnit don't get the pipline to unstable state. A failed test causes the pipline to go to failed status.

            My Pipeline:

            pipeline {
              agent {
                docker {
                  image 'qnib/pytest'
                  args '-v /home/user/git/:/test-reports'
                }
              }
              stages {
                stage('Test') {
                  steps {
                    sh 'pytest --junitxml result.xml testing/'
                  }
                  post {
                    always {
                      junit 'result.xml'
                    }
                  }
                }
              }
            }

            Show
            iko IKO BH added a comment - - edited Andrew Bayer I use JUnit 1.24 and still failed tests captured by JUnit don't get the pipline to unstable state. A failed test causes the pipline to go to failed status. My Pipeline: pipeline {   agent {     docker {       image 'qnib/pytest'       args '-v /home/user/git/:/test-reports'     }   }   stages {     stage('Test') {       steps {         sh 'pytest --junitxml result.xml testing/'       }       post {         always {           junit 'result.xml'         }       }     }   } }
            Hide
            dnussbaumer Dan Nussbaumer added a comment -

            This bug still exists in version 1.24

            Show
            dnussbaumer Dan Nussbaumer added a comment - This bug still exists in version 1.24

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                therealwaldo Will Freeman
              • Votes:
                1 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated: