The Workspace Cleanup
plugin is used to delete the workspace from Jenkins before the build, or when a build is finished and artifacts saved. If we want to start a Jenkins build with a clean workspace, or we want to clean a particular directory before each build, then we can effectively use this plugin. Different options are available for deleting workspaces.
Install the plugin from the Jenkins dashboard:
We can apply patterns for files to be deleted based on the status of the build job. We can add post-build actions for workspace deletion:
Note
For more details on the Workspace Cleanup
plugin, visit https://plugins.jenkins.io/ws-cleanup.