因此,我正在使用Jenknis JUnit解析器插件来解析测试结果。我的工作只有一项测试,并且一直失败。但是,JUnit插件将作业标记为不稳定且未失败。
任何原因吗?
我尝试将“运行状况”报告放大系数设置为1、0.1、0.0,但是没有运气。似乎这就是为什么我的工作被报告为不稳定且未失败的原因。
如何使JUnit生成失败?
谢谢!
答案 0 :(得分:1)
以下变通办法对我有效:
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"
}
}
}
答案 1 :(得分:0)
不幸的是,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)
答案 2 :(得分:0)
如果测试在容器中运行并且想要从容器上的退出代码获取测试状态,则可以使用以下命令
test_status=$(docker inspect <containerName/ID> --format='{{.State.ExitCode}}')
exit $test_status