-
Notifications
You must be signed in to change notification settings - Fork 411
/
findStaleFolders.groovy
51 lines (45 loc) · 1.32 KB
/
findStaleFolders.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
44
45
46
47
48
49
50
51
import groovy.time.TimeCategory
import com.cloudbees.hudson.plugins.folder.Folder
now = new Date()
definitionOfStaleInDays = 100
def jenkinsFolders = Jenkins.instance.getAllItems(Folder)
jenkinsFolders.each { folder ->
if(isStaleFolder(folder)){
println "${folder.name} IS A STALE FOLDER ${constructParentPath(folder)}"
}
}
boolean isStaleFolder(folder){
boolean returnValue
use(TimeCategory) {
for(job in folder.getAllJobs()) {
Run lastBuild = job.getLastBuild();
if (lastBuild == null) {
//Job has never run
continue
}
if (lastBuild.getTime() > now - definitionOfStaleInDays.days) {
returnValue = false
break
}else{
returnValue = true
}
}
}
return returnValue
}
String constructParentPath(Folder folder){
if(folder.getParent().getDisplayName() == "Jenkins"){
return "That is under ROOT"
}
parentPath = 'That is under '
def parent = folder.getParent()
String displayName = parent.getDisplayName()
while(displayName != "Jenkins") {
parentPath <<= "${displayName} under "
parent = parent.getParent()
displayName = parent.getDisplayName()
}
parentPath <<= "ROOT"
return parentPath
}
return