Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a cleanup script on exec-maven-plugin:exec failure?

I'm currently using the maven plugin exec-maven-plugin to execute a script, this script launches several java programs corresponding to an integration test, if the test passes, everything is stopped properly by a cleanup script executed later in the build.

My problem is when the test fails because when the plugin exec-maven-plugin fails it stops the build immediately such that my cleanup script is never called which means that my java programs are never stopped.

So is there a way to execute my cleanup script even if my integration test fails?

So far, I added 1 as successCode to my integration test to ensure that my cleanup script is called but it is not good enough because the build is seen has a build success which is not the case.

Any ideas?

like image 942
Nicolas Filotto Avatar asked Jan 28 '26 22:01

Nicolas Filotto


1 Answers

Here is what I finally did:

  1. I added 1 as success code to my integration test in order to make sure that the cleanup script is always called.
  2. I defined the property outputFile to my integration test in order to redirect the standard output streams into a file to be tested later
  3. After my cleanup script, I check for a given pattern in file created in step #2 using a command of type cat {my-file} | grep {my-pattern} >/dev/null in order to know if the integration test passed or not, if the pattern cannot be found, it will make the build fails otherwise the build will pass.
like image 179
Nicolas Filotto Avatar answered Feb 01 '26 02:02

Nicolas Filotto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!