Search code examples
jenkinscontinuous-integrationjenkins-pipelinejenkins-plugins

Jenkins - Builds always unstable when some test failed even though it must fail


I am using the Junit plugin for the tests report. My problem is most of the builds will mark as unstable which should be failed. Is there any way to mark the build as failed when having more than one test failed?

Example1:

Example2:

Example3:


Solution

  • As of now, there is no directly configurable threshold option for the JUnit plugin in Jenkins (Here is the open feature request). However, you can add an if condition after reporting the test results and set the build status.

    def junitTestSummary = junit testResults: "**/*.xml"
    // junitTestSummary.[failCount, totalCount, skipCount, passCount]
    if(junitTestSummary.failCount>0){
       error("Failing the pipeline. Because, there are ${junitTestSummary.failCount} tests failed")
     }