Jenkins の Ant から testng xml にパラメータを渡す
Jenkins の「このビルドはパラメーター化されています」機能を使用すると、テスト パラメーター (テスト構成やデータ入力など) を Ant 経由で動的に渡すことができます。
Here is how-to:
-
In Jenkins, config job and enable “This build is parameterised” and config a set of variables;
Note: These variables are available as env. vars and should be accessed by os shell as well as by tools like Ant and etc.
-
In Jenkins, config job build with Ant and upon job execution, the parameters configured in step 1 are automatically appended to Ant command as properties:
$ ant -Dvar1=value1 -Dvar2=value2 … -DvarN=valueN runTest
-
In testng.xml file:
- Do not define
for the above variables that are intended to be parameterised in Jenkins; - If defined in testng.xml file, the values defined in Jenkins will be overriden by those in testing xml file
- Do not define
-
Important step: in Ant build.xml when defining the
target, ensure the “delegateCommandSystemProperties” attribute is set to “true”, e.g.
<target name="runTest" depends="compile">
<testng classpath="${cp}:${build.dir}" delegateCommandSystemProperties="true">
<xmlfileset dir="${test-cases.dir}" includes="testng.xml"/>
</testng>
</target>
- Important notice: In order for jenkins/ant to pass the parameters to testng, the parameters in testng java methods should be defined with @Parameters tag (The ITestContext will not work), refer to discussion for more.