-
Notifications
You must be signed in to change notification settings - Fork 1
/
countBuilds.groovy
37 lines (28 loc) · 1.22 KB
/
countBuilds.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
// author : Ivan Audisio
// List the number of builds for each job in the past X days
import groovy.time.TimeCategory
import java.text.SimpleDateFormat;
days = 10
def start = new Date()
start = start.getTime()
def end = new Date() - days
end = end.getTime()
jobs = Jenkins.instance.getAllItems() // Get all jenkins items
println("------------------------------------------------------------------------")
println("The following jobs have not executed since ")
println("------------------------------------------------------------------------")
println("")
jobs.each {job ->
def count = 0
// Verify that the item contains the method getLastBuild (avoids templates and folders)
if (job.metaClass.getMetaMethod("getLastBuild")) {
// Verifies that the job has been build at leat once
builds = job.getBuilds().byTimestamp(end, start)
builds.each{build -> count ++}
println("Name : ${job.name} (${count} builds)")
}
}
println("------------------------------------------------------------------------")
println("${count} Job(s) have not been executed since ")
println("${countNotBuild} Job(s) do not have any build history")
println("------------------------------------------------------------------------")