I am trying to execute a shell script that sends our testing results to 3rd party. We are running the tests in Jenkins pipeline, and the tests are running via Cucumber. Also, we are using maven-surefire-plugin to run the tests, and exec-maven-plugin to execute the shell script.
The expected flow is:
- Jenkins pipeline run a "mvn install" command
- maven-surefire-plugin runs all the tests
- Regardless of the tests results (success/failure) a shell script will be executed and it will get the report file and upload it to a 3rd party software
However, it looks like that if one of the tests failed, the exec-maven-plugin doesn't execute shell script. Meaning, step 3 doesn't succeed.
Here is a partial POM.xml file of the module:
<profiles>
<profile>
<id>cucumber-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M7</version>
</dependency>
</dependencies>
<configuration combine.self="override">
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*CucumberRunner.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Shell Script</id>
<phase>----some phase------</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>wsl</executable>
<arguments>
<argument>sh</argument>
<argument>-c</argument>
<argument>${PWD}/src/test/resources/scripts/shellScript.sh</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Every time we use the command:
mvn -B install -P cucumber-tests
The surefire plugin runs the tests, and if everything passes the shell script also being executed (phases that we've tested are "test", "integration-test" and "verify"), but if something fails, maven doesn't execute the script.
We've also tried skipping tests (doesn't help because the result is Successful), using -fae/--fail-at-end flag (did nothing) and running a java code instead of shell script, but nothing worked so far.
Is what we're trying to achieve even possible? Are we missing something?
To ignore test failures you can use:
But as it explains in the documentation: