Jenkins Snippets

Wipe out workspaces for all projects:
Thanks to Stefan Bäumler at https://wiki.jenkins-ci.org/display/JENKINS/Wipe+out+workspaces+of+all+jobs, I made a copy right here.

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

Delete all builds for all projects:
We tweak the script above to delete all builds.

import hudson.model.*
// For each project
for(item in Hudson.instance.items) {
  // check that job is not building
  if(!item.isBuilding()) {
    println("Wiping out builds of job "+item.name)
      item.builds.each { it.delete() }
  }
  else {
    println("Skipping job "+item.name+", currently building")
  }
}
Download PDF
This entry was posted in Jenkins, Snippets. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *