-
Notifications
You must be signed in to change notification settings - Fork 1
/
BulkDeleteViews.groovy
43 lines (35 loc) · 1.16 KB
/
BulkDeleteViews.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*** BEGIN META {"name" : "Bulk delete of views",
"comment" : "It will delete all views provided and optionally the jobs inside them (dry run mode available)",
"parameters" : [ 'dry', 'views', 'deleteJobs' ],
"core": "2.0",
"authors" : [{ name : "Luis del Toro" }]} END META**/
import jenkins.model.*
dry = dry.toBoolean()
println "Dry Run mode: $dry"
views = views.split(',')
println "Views To Delete: $views"
deleteJobs = deleteJobs.toBoolean()
println "Delete Jobs Mode: $deleteJobs"
def jenkins = Jenkins.instance
def deletedViews = 0
def deletedJobs = 0
views.each {
def view = jenkins.getView(it.trim())
println "Candidate for deletion found: view '${view.name}'"
if (deleteJobs) {
view.items.each {
println "Candidate for deletion found: job '${it.name}' in view '${view.name}'"
if (!dry) {
it.delete()
deletedJobs++
println "Job '${it.name}' deleted"
}
}
}
if (!dry) {
view.owner.deleteView(view)
deletedViews++
println "View '${view.name}' deleted"
}
}
println "Deleted ${deletedViews} views and ${deletedJobs} jobs"