简体   繁体   中英

Is it possible to pass testng.xml and test name as single parameter in Jenkins?

I have below testng.xml file :

<test name="Product_Listing_Page" enabled="true">
    <parameter name="scenario.file.loc" value="scenarios/plp.bdd"></parameter>
    <groups>
        <run>
            <include name="REGRESSION" />
        </run>
    </groups>

    <classes>
        <class name="client.text.BDDTestFactory"></class>
    </classes>
</test>

<test name="Registration" enabled="false">
    <parameter name="scenario.file.loc" value="scenarios/registration.bdd"></parameter>
    <groups>
        <run>
            <include name="REGRESSION" />
        </run>
    </groups>
    <classes>
        <class name="client.text.BDDTestFactory"></class>
    </classes>
</test>

I have create one Jenkins job as maven project where I'am passing the testng.xml file name as parameter like clean test -DSuiteXmlFile=config/testrun_config.xml because I have also configured failed-test.xml in Post build trigger as well. I'm looking for a way where i can pass the test name along with the command.

Any idea about this or do i need to try some other approach ?

Pass multiple parameters from Jenking to maven using below command:

clean install compile test -DsuiteXmlFile=$TestNgFile -DOtherParamerer1=$ValueOfParameter1 -DOtherParameter2=$ValueOfParameter2 

This passes like below image: 在此处输入图片说明

Receive these value in pom.xml using below:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <skip>false </skip>
                <forkCount>0</forkCount>
                    <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                        <systemProperties>
                    <property>
                        <name>ValueOfParameter1</name>
                        <value>${OtherParamerer1}</value>
                    </property>
                    <property>
                        <name>ValueOfParameter2</name>
                        <value>${OtherParameter2}</value>
                    </property>
                </systemProperties>
            </configuration>
        </plugin>

And these value can be read in any javaFile or other language programs:

static String  ValueOfParameter1=System.getProperty("ValueOfParameter1");
static String ValueOfParameter2= System.getProperty("ValueOfParameter2");

Let me know if it solves your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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