繁体   English   中英

如何创建Maven配置文件并根据激活的配置文件使用不同的XML套件运行每个配置文件?

[英]How to create maven profile & run each profile with different XML suites according to the profile activated?

我是Maven和Maven个人资料的新手。 我正在从事自动化Maven项目,并且正在尝试创建其他概要文件。 我想做的是,每个配置文件将根据激活的配置文件运行不同的xmlsuites。

<profiles>
    <profile>
        <id>Jenkins</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.17</version>
                    <configuration>
                        <includes>
                            <include>**/*.java</include>
                        </includes>
                        <suiteXmlFiles>
                            <echo>Jenkins profile</echo>
                            <suiteXmlFiles>xml/jenkins.xml</suiteXmlFiles>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

    <profile>
        <id>Ticket</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.17</version>
                    <configuration>
                        <includes>
                            <include>**/*.java</include>
                        </includes>
                        <suiteXmlFiles>
                            <echo>Ticket profile</echo>
                            <suiteXmlFiles>xml/Tickets.xml</suiteXmlFiles>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

以上是我所做的。 我希望任何人都可以帮助我指出如何做。

现在,在jenkins上运行自动化时出现以下错误:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-         plugin:2.17:test (default-test) on project ipos: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: There was an error in the forked process
[ERROR] org.apache.maven.surefire.testset.TestSetFailedException: Suite file C:\Program Files (x86)\Jenkins\workspace\Automatizacion IPOS\Ticket profile is not a valid file
[ERROR] at org.apache.maven.surefire.testng.TestNGXmlTestSuite.locateTestSets(TestNGXmlTestSuite.java:116)
[ERROR] at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:84)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
[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.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:

谢谢

然后,最干净的实现是对插件进行单一配置以运行每个构建,并简单地定义一个属性标记,该标记在一个配置文件与另一个配置文件之间有所不同。

<profiles>
    <profile>
        <id>Jenkins</id>
        <properties>
            <my.echo>Jenkins profile</my.echo>
            <my.xml.files>xml/jenkins.xml</my.xml.files>
        </properties>
    </profile>

    <profile>
        <id>Ticket</id>
        <properties>
            <my.echo>Ticket profile</my.echo>
            <my.xml.files>xml/Tickets.xml</my.xml.files>
        </properties>
    </profile>
</profiles>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <includes>
                    <include>**/*.java</include>
                </includes>
                    <suiteXmlFiles>

<!-- DELETE THIS LINE: IS A TYPO
                    <echo>Ticket profile</echo>
-->

<!-- PROFILE-DRIVEN SUBSTITUTION -->
                        <echo>${my.echo}</echo>
                        <suiteXmlFiles>${my.xml.files}</suiteXmlFiles>
                    </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

希望能有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM