user481572
user481572

Reputation:

How to clean Jenkins workspace only if build fails

In the interest of reducing build times I would like to only clean down the Jenkins job workspace if a build fails. Is there of doing this using post build action? Does Jenkins set a variable to the effect of 'BUILD FAILED' that can be read in a script that could be use in the post build action section of the job config?

Thanks in advance.

Upvotes: 3

Views: 3618

Answers (2)

Oliver Gondža
Oliver Gondža

Reputation: 3511

Workspace Cleanup Plugin has an option just for that. Add its post build step, tick particular checkbox and it will clean only failed (unstable?) builds.

Upvotes: 3

Slav
Slav

Reputation: 27485

Post-build Task plugin can read your console output and execute scripts if regex is found. When a build step fails, it will print "BUILD FAILED" into console output.

Configure post-build task to look for that, and execute the cleanup in that case.

Upvotes: 3

Related Questions