[英]Jenkins JUnit Plugin reports a build as unstable even if test fails
所以我使用 Jenknis JUnit 解析器插件来解析测试结果。 我有一份只有一次测试的工作,但它一直都失败了。 但是,JUnit 插件将作业标记为不稳定且未失败。
有什么理由吗?
我曾尝试将健康报告放大系数设置为 1、0.1、0.0,但没有成功。 似乎这就是为什么我的工作被报告为不稳定而不是失败的原因。
如何让 JUnit 使构建失败?
谢谢!
以下解决方法对我有用:
sh "test ${currentBuild.currentResult} != UNSTABLE"
我在 junit 步骤之后添加了它。 所以最后你的管道看起来类似于这样:
stage('test') {
steps {
sh "mvn -Dmaven.test.failure.ignore=true -DtestFailureIgnore=true test"
}
post {
success {
junit '**/target/surefire-reports/**/*.xml'
sh "test ${currentBuild.currentResult} != UNSTABLE"
}
}
}
不幸的是,JUnit 记者不支持构建失败。 这非常令人沮丧,因为这是一种流行的用例......
在任何情况下,您都需要实施解决方法。 所以你要么:
保存测试工具的退出代码,稍后构建失败。 您可以为任何类型的工作(包括管道)执行此操作。 对于通常的工作, Execute shell
步骤看起来像这样:
set +e # Disable the option to fail the job when any command fails phpunit # Run the tests unit_tests_exit_code=$? # Save the exit code of the last command set -e # Re-enable the option to fail the job when any command fails echo "yolo" # Execute everything you want to run before you fail the job exit $unit_tests_exit_code # You fail the job (if test run failed and phpunit returned a non-zero exit code)
如果测试在容器内运行,并且想要从容器上的退出代码获取测试状态,则可以使用以下命令
test_status=$(docker inspect <containerName/ID> --format='{{.State.ExitCode}}')
exit $test_status
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.