gpt4 book ai didi

java - Jenkins 会吞下 MojoFailureException 吗?

转载 作者:行者123 更新时间:2023-11-30 07:33:19 24 4
gpt4 key购买 nike

我已经使用参数配置了 Maven Surefire 插件:

<configuration>
<forkedProcessTimeoutInSeconds>60</forkedProcessTimeoutInSeconds>
</configuration>

因此,当测试运行超过 60 秒时,surefire 插件会中断它。

当我使用 mvn testmvn install 时,一切都在我的本地计算机上完美运行,但是当我尝试在 Jenkins 上构建项目时,它只会吞掉异常,写入日志[ERROR] fork 中出现超时或其他错误并继续构建。结果我收到一条 Finished: SUCCESS 消息。

问题:有人遇到这个问题吗?有谁知道有什么解决办法吗?

最佳答案

maven 本地构建和 Jenkins maven 作业的默认选项之间的一个重要区别是,本地 maven.test.failure.ignore Maven Surefire 插件的选项设置为 false (合理),这样测试失败也会导致构建失败。

来自official documentation :

Set this to "true" to ignore a failure during testing. Its use is NOT RECOMMENDED, but quite convenient on occasion.

但是,Maven Jenkins 作业将始终运行,将相同的选项设置为 true,这样即使测试失败,Maven 构建也会成功,并将 Jenkins 作业的状态变为 UNSTABLE (而不是成功失败,这确实可能是一个争论点)。

此行为也记录在官方 Jenkins 问题 ticket

Following the Jenkins Terminology, when (surefire or failsafe) tests fail, the Jenkins build status must be UNSTABLE:
<< A build is unstable if it was built successfully and one or more publishers report it unstable. For example if the JUnit publisher is configured and a test fails then the build will be marked unstable. >>

因此,在 Maven Jenkins 作业中,如果测试失败:

  • Maven 构建成功
  • Jenkins 版本不稳定

相反,在执行 Maven 的自由式 Jenkins 作业中,如果测试失败:

  • Maven 构建失败
  • Jenkins 构建失败

可能的解决方案:

  • 将构建更改为运行 Maven 的自由式 Jenkins 作业(但这可能工作量太大)或
  • -Dmaven.test.failure.ignore=false 选项添加到您的构建中(但是,您将不再拥有 UNSTABLE 构建)。

关于java - Jenkins 会吞下 MojoFailureException 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35752223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com