当 junit 失败时将构建标记为不稳定



我部署了一个具有JUnit测试的maven项目。当测试失败时,生成将标记为FAILED。但是,我希望在测试失败时将其标记为UNSTABLE,并在出现严重错误时将其标记为FAILED。 这是我的Jenkinsfile

node{
stage ('Checkout')
{
checkout scm
}
stage ('Build')
{
try {
sh '''
mvn clean -B org.jacoco:jacoco-maven-plugin:prepare-agent install
'''
currentBuild.result = 'SUCCESS'
} catch (Exception AssertionError) {
currentBuild.result = 'UNSTABLE'
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
}
}
}

但这对我不起作用。我无法抓住AssertionError并且构建始终标记为FAILED.有什么想法吗?谢谢。

您可以使用 xunit 插件而不是 junit 插件,您可以配置该插件以将构建设置为不稳定,以防特定数量的测试失败。

最新更新