How can I cleanup the workspace in Jenkins? I am using AccuRev as version control tool.

I created freestyle projects in Jenkins.

share|improve this question

There is a way to cleanup workspace in Jenkins. You can clean up the workspace before build or after build.

First, install Workspace Cleanup Plugin.

To clean up the workspace before build: Under Build Environment, check the box that says Delete workspace before build starts.

To clean up the workspace after the build: Under the heading Post-build Actions select Delete workspace when build is done from the Add Post-build Actions drop down menu.

share|improve this answer
    
Thanks a lot Nagendra. I am able to fix this issue using workspace cleanup plugin. – Karthik Mar 4 '15 at 6:28

If you want to manually clean it up, for me with my particular version of jenkins (I didn't appear to need an extra plugin installed for this, but who knows), there is a "workspace" link on the left column, click it, then a "Wipe out current workspace" link appears beneath it on the left hand side column.

share|improve this answer

Beside above solutions, there is a more "COMMON" way - directly delete the largest space consumer from Linux machine. You can follow the below steps:

  1. Login to Jenkins machine (Putty) enter image description here
  2. cd to the Jenkins installation path

Using ls -lart to list out hidden folder also, normally jenkin installation is placed in .jenkins/ folder

[xxxxx ~]$ ls -lart

drwxrwxr-x 12 xxxx  4096 Feb  8 02:08 .jenkins/
  1. list out the folders spaces

Use df -h to show Disk space in high level

du -sh ./*/ to list out total memory for each subfolder in current path.

du -a /etc/ | sort -n -r | head -n 10 will list top 10 directories eating disk space in /etc/

  1. Delete old build or other large size folder

Normally ./job/ folder or ./workspace/ folder can be the largest folder. Please go inside and delete base on you need (DO NOT delete entire folder).

rm -rf theFolderToDelete

enter image description here

share|improve this answer
1  
Not sure why voted down. This sounds like a good option for Jenkins admins. Agree not for "read-only" users. – lean_programmer May 12 '17 at 16:12
    
1. This doesn't really answer the question asked and 2. my Jenkins server is running on Windows. – mjaggard Jun 7 '17 at 9:15
2  
@mjaggard The question was asked by some one else and he did not mention if it is for Windows only. Also he asked how to cleanup workspace (not limited to frontend/client). Am I missing anything obvious here? – lean_programmer Jun 8 '17 at 4:22
2  
I totally agree with @takias, it seems a valid answer for the question. And a good one if you have enough permission to do it. – PhoneixS Jul 18 '17 at 14:54

You can run the below script in the Manage JenkinsScripts Console for deleting the workspaces of all the jobs at one shot. We did this to clean up space on the file system.

import hudson.model.*
// For each project
for(item in Hudson.instance.items) {
  // check that job is not building
  if(!item.isBuilding()) {
    println("Wiping out workspace of job "+item.name)
    item.doDoWipeOutWorkspace()
  }
  else {
    println("Skipping job "+item.name+", currently building")
  }
}
share|improve this answer
    
this does not work for me, it shows java.lang.NullPointerException: Cannot get property 'items' on null object . – Vincent Gerris Nov 28 '17 at 9:33

You will need to install this plugin before the options mentioned above will appear

Workspace Cleanup Plugin

This plugin add the check box to all job configs to allow you to delete the whole workspace before any steps (inc source control) are run

This is useful to make sure you always start from a known point to guarantee how you build will run

share|improve this answer
1  
Please add some information that your link is containing. Link-only answer are not what we are looking for at SO! :) – Chilion Feb 26 '15 at 8:26
    
Thanks a lot Keir. It works for me. – Karthik Mar 4 '15 at 6:28
    
This add's no more information that this answer hasn't already covered. In fact it add's a lot less – Liam Dec 14 '17 at 15:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.