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.
[code language=”groovy”]
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”)
}
}
[/code]

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

[code language=”groovy”]
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”)
}
}
[/code]

This entry was posted in Jenkins, Snippets. Bookmark the permalink.

Leave a Reply

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