Reputation: 171
How can I pass a parameter from Jenkins to TestNG. I want to pass the application URL as a parameter to my testNg file. The reason I want to do this is to run tests simultaneously on multiple test environments.
At the moment the url is in the testNg xml file
Here is a snapshot of my POM
<plugins>
<!-- surefire plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
src/test/resources/testng.xml
</suiteXmlFiles>
<filtering>true</filtering>
</configuration>
</plugin>
Upvotes: 1
Views: 2349
Reputation: 105
You can use an environment variable for that purpose.
By having a look at the Jenkins documentation for Parametrized Build, one can set parameters on builds. These are then made available as environment variables during the build.
In case your are using Maven, in order to have TestNG use the environment variable, you can apply filtering to the XML file. Filtering will replace any occurrence of, for example, ${URL}
, with the value of the URL
environment variable.
Please check this answer to understand how to do it.
Upvotes: 2