Issue
I use Java Selenium WebDriver with TestNG for running my tests.
I am calling driver.quit()
in my final test to make sure the files created in /tmp/
folder are deleted.
However, if there is an aborted run (via Jenkins
), the contents in /tmp/
folder are not deleted.
Is there a testng listener or any other way I can make sure that tmp
folder is cleared even if the run is aborted mid-run?
Solution
If the issue introduced on Jenkins level (aborting action), I believe, more effective will be solve this also with Jenkins, not with TestNG Listener.
For declarative pipeline
pipeline {
agent any
stages {
...
}
post {
aborted {
script {
echo 'cleanup on abort'
// this will clean workspace
// cleanWs()
//or just delete 'tmp' directory
dir ('tmp') {
deleteDir()
}
}
}
}
}
Using Plugin
https://plugins.jenkins.io/postbuild-task/
Install plugin and setup shell script execution for the job like
rm -rf tmp
Answered By - Max Daroshchanka
Answer Checked By - Willingham (JavaFixing Volunteer)