所以这个问题有点模糊,我很抱歉,但我真的不知道从哪里开始。我们使用 Jenkins 在夜间自动化一些构建。我们使用 Maven 执行构建。有一段时间,一切都很顺利。我们有发现错误、代码覆盖率结果以及成功构建的稳定历史。突然之间,在运行单元测试时,我们似乎得到了随机的 NoClassDefFound 异常。这很奇怪,因为在此之前,日志消息清楚地显示它正在构建源并成功。然后单元测试开始运行,它们立即因上述异常而死亡。我们最近确实对 Jenkins 进行了更新,但我并不完全相信这与此有很大关系。真正奇怪的是,构建并不总是因为这个异常而失败。有时他们跑得很好并通过,有时他们立即失败。就失败的特定单元测试或无法找到的特定类而言,失败并不一致。虽然它们似乎围绕着相同的一小组类和单元测试,但似乎没有任何真正的模式。
还有其他人在 jenkins 上使用 Maven 构建过这种情况吗?我真的不知道该怎么办。日志消息并不完全有用,而且我不知道可以对 Jenkins 配置做些什么来从失败的构建中获取更好的调试信息。如果有人有任何想法,我可以收集任何人可能需要的任何信息。以下是最近失败的构建之一的示例堆栈跟踪:
com.ipti.ptl.common.problems.detectors.CMDRProblemDetectorTest.afterPropertiesSetTest
Failing for the past 3 builds (Since Unstable#411 )
Took 18 ms.
Error Message
com/ipti/hardware/bcicinterface/CPacketReceivedArgs
Stacktrace
java.lang.NoClassDefFoundError: com/ipti/hardware/bcicinterface/CPacketReceivedArgs
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
at java.lang.Class.getDeclaredMethods(Class.java:1845)
at com.ipti.common.eventbus.EventBus.subscribe(EventBus.java:107)
at com.ipti.ptl.common.problems.detectors.CMDRProblemDetector.afterPropertiesSet(CMDRProblemDetector.java:23)
at com.ipti.ptl.common.problems.detectors.CMDRProblemDetectorTest.afterPropertiesSetTest(CMDRProblemDetectorTest.java:37
最佳答案
我也经历过类似的事情。我们学到了两个保持一致性的重要技巧:
- 将构建配置为每次构建时“ checkout 新源”。有时事情可能会变得陈旧
- 检查您是否使用
clean package
或clean install
。install
会将 Artifact 存储在运行 Jenkins 的用户本地的.m2
存储库中。如果不是,任何给定的项目都可能必须在构建期间从您配置的存储库下载其依赖项。我建议使用clean install
只是为了让本地 Artifact 就位,为依赖构建做好准备。
根据这两条规则仔细检查每个 Jenkins 构建非常重要。相互依赖的项目之间的不一致也是随机困惑的根源。
关于java - Jenkins 上的随机构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22353669/