Today we are going to jump a little bit in CI/CD with a generic jenkins runner based on cucumber tags. In this post will be detailed explained how to configure the runner and how to create the generic profile on real project, let’s start…
Creating maven profile based on failsafe plugin to run CucumberRunner.
The profile will contains the maven-failsafe-plugin
to run java test, and how you know the cucumber runners is a simple java test.
In cucumber options we have [CDATA[${tags}]]
here we will send tag name with -D options, Let’s consider an example : -Dcucumber.options=”–tags @UI “.
<profile>
<id>generic-runner</id>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/RunAllTests.java</include>
</includes>
<argLine>-Xmx1024m -Dfile.encoding=${project.build.sourceEncoding}</argLine>
<systemPropertyVariables>
<cucumber.options><![CDATA[${tags}]]></cucumber.options>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
After adding the profile the <tags>--tags ~@ignore</tags> parameter should be add in pom.xml property.
Configure jenkins job:
An important part of jenkins job is to start our profile with maven command:
In order to run test based on another tag, just change the @UI tag from following mvn command: clean install -Pgeneric-runner -Dcucumber.options=”–tags @UI “.
Or you can add multiple tags on your jenkins execution. Hope this will help you to improve your testing CI/CD.