forked from ivanaudisio/Jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotRun.groovy
More file actions
57 lines (52 loc) · 1.99 KB
/
notRun.groovy
File metadata and controls
57 lines (52 loc) · 1.99 KB
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
52
53
54
55
56
57
// author : Ivan Audisio
// list jobs not run in the last N days / last N months
import groovy.time.TimeCategory
use(TimeCategory) {
// e.g. find jobs not run in last 6 months
//timeFrame = (new Date() - 6.months)
// e.g. find jobs not run in last 3 hours
//timeFrame = (new Date() - 3.hours)
// e.g. find jobs not run in last day
//timeFrame = (new Date() - 1.days)
timeFrame = (new Date() - 6.months)
}
jobs = Jenkins.instance.getAllItems() // Get all jenkins items
def count = 0
def countNotBuild = 0
println("------------------------------------------------------------------------")
println("The following jobs have not executed since ${timeFrame}")
println("------------------------------------------------------------------------")
println("")
jobs.each {job ->
// 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
if (job.getLastBuild()){
if (job.getLastBuild().getTime() < timeFrame) {
count ++
println("Name : ${job.name}")
println("Class : ${job.class}")
println("Root Dir : ${job.rootDir}")
println("URL : ${job.url}")
println("Absolute URL: ${job.absoluteUrl}")
println("Last Build : " + job.getLastBuild().getTime())
println("")
println("")
}
} else {
countNotBuild ++
println("Name : ${job.name}")
println("Class : ${job.class}")
println("Root Dir : ${job.rootDir}")
println("URL : ${job.url}")
println("Absolute URL: ${job.absoluteUrl}")
println("Last Build : There is no build history for this Job")
println("")
println("")
}
}
}
println("------------------------------------------------------------------------")
println("${count} Job(s) have not been executed since ${timeFrame}")
println("${countNotBuild} Job(s) do not have any build history")
println("------------------------------------------------------------------------")