We are running Jenkins 2.x and love the new Pipeline plugin. However, with so many branches in a repository, disk space fills up quickly.
Is there any plugin that's compatible with Pipeline that I can wipe out the workspace on a successful build?
You can use deleteDir()
as the last step of the pipeline Jenkinsfile (assuming you didn't change the working directory).
I have problems with deleteDir(). It seems to randomly not able to delete the current directory when the node gets build on a slave. The build fails of course if this happens. So be aware if your jobs fail randomly. I don't understand why node not just cleans it workspace when the node starts building. Because the node can run anywhere you can't make any assumptions about the files in the workspace anyway.
I put this at the beggining right before
checkout scm
.I put this at the beginning also, in case the project fails before it reaches the end, or the next build is on a different slave.
This is the command documented to clean up the workspace in the "Cleaning up and notifications" section of the Jenkins documentation.
Beware
deleteDir()
won't work in a docker container. JENKINS-41894