我需要能够在Jenkins的工件上运行Maven release:prepare / release:perform,而无需运行其JUnit测试。
我的测试pom.xml中的Surefire配置
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</execution>
</executions>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</plugin>
Apache’s Surefire documentation建议使用mvn install -DskipTests或mvn install -Dmaven.test.skip = true。当我运行安装程序时,两者都可以工作:
mvn clean install -Dsurefire.testFailureIgnore=true --show-version --batch-mode -e
但是当我在release:perform上尝试使用它们时,这两个参数都无效。
我尝试了以下命令:
mvn -DpreparationGoals=clean release:prepare release:perform -DskipTests -e --batch-mode --show-version -Dusername=**** -Dpassword=**** -Dresume=false
我希望跳过测试,并且release:perform成功。相反,测试会运行并失败(请参见下文),从而导致整个release:perform失败。
mvn -DpreparationGoals=clean release:prepare release:perform -Dmaven.test.skip=true -e --batch-mode --show-version -Dusername=**** -Dpassword=**** -Dresume=false
我希望跳过测试,并且release:perform成功。相反,测试会运行并失败(请参见下文),从而导致整个release:perform失败。
mvn -DpreparationGoals=clean release:prepare release:perform -Dsurefire.testFailureIgnore=true -e --batch-mode --show-version -Dusername=**** -Dpassword=**** -Dresume=false
这不是理想的选择(因为JUnit测试已经运行,因此无需重新运行它们),但是如果忽略JUnit结果,则release:perform可以成功执行,那么现在就可以解决。测试并没有忽略结果,而是运行并仍然失败,但是导致整个release:perform失败。
mvn -DpreparationGoals=clean release:prepare release:perform -fn -e --batch-mode --show-version -Dusername=**** -Dpassword=**** -Dresume=false
这也不理想。它的确允许release:perform成功完成,但是如果release:perform出于除JUnit测试失败以外的其他原因而失败,则最终用户将无法得到通知。
以下是运行release:prepare release:perform -DskipTests或release:prepare release:perform -Dmaven.test.skip = true的输出:
+ mvn -DpreparationGoals=clean release:prepare release:perform -DskipTests -e --batch-mode --show-version -Dusername=**** -Dpassword=**** -Dresume=false
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T11:29:23-06:00)
…
Java version: 1.7.0_71, vendor: Oracle Corporation
…
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.11.6.el7.x86_64", arch: "amd64", family: "unix"
[INFO] [INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ TestInvProfileWeb ---
[INFO] [INFO]
[INFO] [INFO] -------------------------------------------------------
[INFO] [INFO] T E S T S
[INFO] [INFO] -------------------------------------------------------
[INFO] [INFO] Running com.investmentprofile.jsf.EndUserBeanTest
[INFO] [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.028 s <<< FAILURE! - in com.investmentprofile.jsf.EndUserBeanTest
[INFO] [ERROR] test1(com.investmentprofile.jsf.EndUserBeanTest) Time elapsed: 0.008 s <<< FAILURE!
[INFO] junit.framework.AssertionFailedError
[INFO] at com.investmentprofile.jsf.EndUserBeanTest.test1(Unknown Source)
[INFO]
[INFO] [INFO]
[INFO] [INFO] Results:
[INFO] [INFO]
[INFO] [ERROR] Failures:
[INFO] [ERROR] EndUserBeanTest.test1:48
[INFO] [INFO]
[INFO] [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] [INFO]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Reactor Summary:
[INFO] [INFO]
[INFO] [INFO] TestInvProfileWebParent ............................ SUCCESS [ 1.622 s]
[INFO] [INFO] TestInvProfileWebClient ............................ SUCCESS [ 8.253 s]
[INFO] [INFO] TestInvProfileWeb .................................. FAILURE [ 5.333 s]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD FAILURE
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 15.396 s
[INFO] [INFO] Finished at: 2018-10-19T13:40:42-05:00
[INFO] [INFO] Final Memory: 48M/600M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project TestInvProfileWeb: There are test failures.
[INFO] [ERROR]
[INFO] [ERROR] Please refer to /opt/Jenkins/workspace/unk_TestInvProfileWebParent-YI772VMG3PH6E767GSGQFPUMCBV45RSLSRI75337QAZHUOO63NUQ/target/checkout/TestInvProfileWebParent/TestInvProfileWeb/target/surefire-reports for the individual test results.
[INFO] [ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[INFO] [ERROR] -> [Help 1]
[INFO] [ERROR]
[INFO] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[INFO] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[INFO] [ERROR]
[INFO] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[INFO] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[INFO] [ERROR]
[INFO] [ERROR] After correcting the problems, you can resume the build with the command
[INFO] [ERROR] mvn <goals> -rf :TestInvProfileWeb
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] TestInvProfileWebParent ............................ FAILURE [ 20.071 s]
[INFO] TestInvProfileWebClient ............................ SKIPPED
[INFO] TestInvProfileWeb .................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.508 s
[INFO] Finished at: 2018-10-19T13:40:42-05:00
[INFO] Final Memory: 15M/210M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5:perform (default-cli) on project TestInvProfileWebParent: Maven execution failed, exit code: '1' -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5:perform (default-cli) on project TestInvProfileWebParent: Maven execution failed, exit code: '1'
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Maven execution failed, exit code: '1'
at org.apache.maven.plugins.release.PerformReleaseMojo.execute(PerformReleaseMojo.java:181)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: org.apache.maven.shared.release.ReleaseExecutionException: Maven execution failed, exit code: '1'
at org.apache.maven.shared.release.phase.AbstractRunGoalsPhase.execute(AbstractRunGoalsPhase.java:89)
at org.apache.maven.shared.release.phase.RunPerformGoalsPhase.runLogic(RunPerformGoalsPhase.java:135)
at org.apache.maven.shared.release.phase.RunPerformGoalsPhase.execute(RunPerformGoalsPhase.java:46)
at org.apache.maven.shared.release.DefaultReleaseManager.perform(DefaultReleaseManager.java:429)
at org.apache.maven.shared.release.DefaultReleaseManager.perform(DefaultReleaseManager.java:381)
at org.apache.maven.plugins.release.PerformReleaseMojo.execute(PerformReleaseMojo.java:177)
... 21 more
Caused by: org.apache.maven.shared.release.exec.MavenExecutorException: Maven execution failed, exit code: '1'
at org.apache.maven.shared.release.exec.InvokerMavenExecutor.executeGoals(InvokerMavenExecutor.java:394)
at org.apache.maven.shared.release.exec.AbstractMavenExecutor.executeGoals(AbstractMavenExecutor.java:110)
at org.apache.maven.shared.release.phase.AbstractRunGoalsPhase.execute(AbstractRunGoalsPhase.java:81)
... 26 more
如何让Surefire在release:perform期间不运行测试?
关于, 玛诺·库玛(M.Manojkumar)
答案 0 :(得分:1)
首先,我同意以上两个评论。就是说,问题在于您的“ -DskipTests”需要传递给release:perform。您可以通过设置arguments参数来实现:
mvn release:perform -Darguments=-DskipTests