【问题标题】:Maven 3 Jenkins Plugin - "Build Failure" for Hello World exampleMaven 3 Jenkins 插件 - Hello World 示例的“构建失败”
【发布时间】:2014-08-15 08:11:46
【问题描述】:

我是第一次使用 Jenkins/Maven,我正在按照这两个教程一起编写一个 Jenkins 插件:https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorialhttp://cleantestcode.wordpress.com/2013/11/03/how-to-write-a-jenkins-plugin-part-1/

到目前为止,这些是我在 Windows 提示符下输入的命令/数据:

  1. mvn hpi:create -Pjenkins
  2. 输入“org.jenkins-ci.tools”作为 groupId
  3. 输入“hello_world”作为 artifactId
  4. cd hello_world
  5. mvn 安装

第 5 步的结果是“BUILD FAILURE”,输出如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.9:test           (default-test) on project hello_world: There are test failures. [ERROR] 
[ERROR] Please refer to C:\$HOME\hello_world\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR]  
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging.

我已经尝试过“mvn install -DskipTests”,但是这样(我不知道如何表达)命令提示符再也不会出现,并且我无法输入更多命令。

我的问题是:

  1. 我没有修改任何由“mvn hpi:create -Pjenkins”生成的文件,那么什么会导致默认测试失败?
  2. 如果没有“-Pjenkins”标志,命令“mvn hpi:create”也会导致构建失败。添加“-Pjenkins”标志的效果是什么?

提前感谢您的任何回答。

[编辑] 以下是 Surefire 报告的内容:

    -------------------------------------------------------------------------------
Test set: InjectedTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 14.697 sec <<< FAILURE!
org.jvnet.hudson.test.JellyTestSuiteBuilder$JellyTestSuite(org.jvnet.hudson.test.junit.FailedTest)  Time elapsed: 0.012 sec  <<< ERROR!
java.lang.ArrayIndexOutOfBoundsException: -1
    at com.thoughtworks.xstream.core.util.OrderRetainingMap.entrySet(OrderRetainingMap.java:77)
    at java.util.HashMap.putMapEntries(HashMap.java:511)
    at java.util.HashMap.putAll(HashMap.java:784)
    at com.thoughtworks.xstream.core.util.OrderRetainingMap.<init>(OrderRetainingMap.java:36)
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildMap(FieldDictionary.java:135)
    at com.thoughtworks.xstream.converters.reflection.FieldDictionary.fieldsFor(FieldDictionary.java:76)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:127)
    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:149)
    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:108)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
    at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:898)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:887)
    at com.thoughtworks.xstream.XStream.toXML(XStream.java:860)
    at hudson.XmlFile.write(XmlFile.java:179)
    at jenkins.model.Jenkins.save(Jenkins.java:2656)
    at jenkins.model.Jenkins.setNoUsageStatistics(Jenkins.java:988)
    at org.jvnet.hudson.test.HudsonTestCase.setUp(HudsonTestCase.java:320)
    at org.jvnet.hudson.test.JellyTestSuiteBuilder$JellyTestSuite.setUp(JellyTestSuiteBuilder.java:133)
    at org.jvnet.hudson.test.junit.GroupedTest.run(GroupedTest.java:49)
    at junit.framework.TestSuite.runTest(TestSuite.java:255)
    at junit.framework.TestSuite.run(TestSuite.java:250)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
testCliSanity(org.jvnet.hudson.test.PluginAutomaticTestBuilder$CliSanityTest)  Time elapsed: 0.027 sec  <<< ERROR!
java.lang.IllegalStateException: second instance
    at jenkins.model.Jenkins.<init>(Jenkins.java:758)
    at hudson.model.Hudson.<init>(Hudson.java:81)
    at org.jvnet.hudson.test.HudsonTestCase.newHudson(HudsonTestCase.java:469)
    at org.jvnet.hudson.test.HudsonTestCase.setUp(HudsonTestCase.java:312)
    at junit.framework.TestCase.runBare(TestCase.java:139)
    at org.jvnet.hudson.test.HudsonTestCase.runBare(HudsonTestCase.java:290)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.framework.TestResult.run(TestResult.java:125)
    at junit.framework.TestCase.run(TestCase.java:129)
    at junit.framework.TestSuite.runTest(TestSuite.java:255)
    at junit.framework.TestSuite.run(TestSuite.java:250)
    at junit.framework.TestSuite.runTest(TestSuite.java:255)
    at junit.framework.TestSuite.run(TestSuite.java:250)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)

【问题讨论】:

  • 安全报告在C:\$HOME\hello_world\target\surefire-reports中包含什么
  • @KeepCalmAndCarryOn 我已经添加了报告内容。谢谢!

标签: jenkins maven-3


【解决方案1】:

尝试跳过测试,将第 5 个命令更改为: 5. mvn install -DskipTests

【讨论】:

  • 我试过了,并且能够成功构建。你能解释一下为什么跳过测试会影响构建吗? @jussuper
  • 我不知道你的测试中有什么,但这些错误可能是 java 的版本
  • 是的,我认为默认的 Initialized jdk 版本应该是 1.6 ,尝试删除旧的 jdk ,并替换为 JDK 1.7 或更高版本,希望对您有所帮助。
猜你喜欢
  • 2013-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-18
  • 2016-02-21
  • 1970-01-01
相关资源
最近更新 更多