Safely delete the contents of ‘workspace’ and ‘jobs’ in Jenkins

Jenkins

I have inherited a Jenkins server and need to clear some space. I have set a;

post {
   always {
     deleteDir()
   }
 }

on all the jobs. Can I remove old builds safely by deleting the contents of workspace and jobs in the $JENKINS_HOME?

Best Answer

Yes, you can delete the workspaces safely as well as jobs.

The idea of the jobs directory is to allow you to display jobs history, if job history is not important for you then you can delete job directories from there.

You can also use the Workspace Cleaner Plugin in order to delete workspace content before the beginning of a job run.

In addition, you can set a "Post Build Action" in your jobs which is called "Delete workspace when build is done".

You can find more information in this nice blog post.