【问题标题】:Jenkins Maven Project Build shell not availableJenkins Maven 项目构建外壳不可用
【发布时间】:2017-04-11 16:30:44
【问题描述】:

在 Jenkins 中,我使用选择参数插件来允许用户选择他们想要运行的套件。我遇到的问题是,当我尝试更改参数部分中选择的选项以附加目录和 .xml 前缀时,作业失败。如果我将全名放在参数中并将其作为构建数据直接输入,它就可以正常工作。以下是我的 jenkins 设置、pom 和错误。

选择参数数据

Name    choice
Choices CopyFunctionality
        CopyToFunctionality

窗口批处理shell命令

@echo off

set SUITE=%choice%.xml

echo %SUITE%

建立价值观

clean test -PParameterisedBuild -DsuiteXmlFile=${SUITE}

POM 配置文件

<profile>
            <id>ParameterisedBuild</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.19.1</version>
                        <configuration>
                            <suiteXmlFiles>
                                <suiteXmlFile>testNG XML Files\${SUITE}</suiteXmlFile>
                            </suiteXmlFiles>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

Maven 错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project Expert_Models: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process
[ERROR] org.apache.maven.surefire.testset.TestSetFailedException: Suite file C:\Automation Framework\Jenkins\workspace\regression_tests_selectable\testNG XML Files\${SUITE} is not a valid file
[ERROR] at org.apache.maven.surefire.testng.TestNGXmlTestSuite.locateTestSets(TestNGXmlTestSuite.java:98)
[ERROR] at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:120)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[JENKINS] Archiving C:\Automation Framework\Jenkins\workspace\regression_tests_selectable\pom.xml to com.ExpertModels/Expert_Models/0.1-SNAPSHOT/Expert_Models-0.1-SNAPSHOT.pom
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
channel stopped
Finished: FAILURE

【问题讨论】:

    标签: maven jenkins windows-shell


    【解决方案1】:
    1. 从 POM 中排除 suiteXmlFiles 参数,不需要此参数,因为您的系统参数会覆盖它。
    2. 您不需要使用批处理脚本设置 jenkins 参数,jenkins 会为您解析参数。
    3. 将套件参数传递给 maven surefire 插件,例如:

      clean test -PParameterisedBuild -Dsurefire.suiteXmlFile=${choice(或任何你选择的参数名称)}

    附:此外,我建议根据上述信息重新评估配置文件的使用情况,我敢肯定,在 99% 的情况下,您可以简单地避免使用配置文件。

    【讨论】:

      猜你喜欢
      • 2013-02-21
      • 1970-01-01
      • 2016-02-02
      • 2013-11-12
      • 1970-01-01
      • 2010-12-26
      • 2019-12-16
      • 1970-01-01
      • 2017-03-21
      相关资源
      最近更新 更多