Jenkins - 当某些测试失败时构建总是不稳定,即使它必须失败

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

我正在为测试报告使用 Junit 插件。我的问题是大多数构建将标记为不稳定,应该失败。当有多个测试失败时,有什么方法可以将构建标记为失败?

示例 1:

示例 2:

示例 3:

截至目前,Jenkins 中的 JUnit 插件没有可直接配置的阈值选项 (Here is the open feature request)。但是,您可以在报告测试结果后添加 if 条件并设置构建状态。

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")
 }