Jenkins : Wipe out workspaces of all jobs

Useful before you make a copy or backup of your Jenkins installation.

This script wipes out the workspaces of all jobs on your Jenkins server

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")
  }
}