diff options
author | Kelley Spoon <kelley.spoon@linaro.org> | 2022-01-31 04:08:18 -0600 |
---|---|---|
committer | Kelley Spoon <kelley.spoon@linaro.org> | 2022-01-31 05:41:42 -0600 |
commit | 689864df939af879dd95d2faffb01446f5513a37 (patch) | |
tree | 9e5adc58cbbdc537d905fdbbe1e26cb79f9bef92 | |
parent | 296007e24b05ab2e1f1f7b44b01e0a59e99bbe42 (diff) |
queue.groovy
Add in json formatted output.
Also, drop the separate filter script and let the
user define a list of substrings to filter out of
the output by setting FILTER_LIST.
Signed-off-by: Kelley Spoon <kelley.spoon@linaro.org>
-rw-r--r-- | queue-filter-tcwg.groovy | 18 | ||||
-rw-r--r-- | queue.groovy | 50 |
2 files changed, 39 insertions, 29 deletions
diff --git a/queue-filter-tcwg.groovy b/queue-filter-tcwg.groovy deleted file mode 100644 index eb14ad7..0000000 --- a/queue-filter-tcwg.groovy +++ /dev/null @@ -1,18 +0,0 @@ -def queue = Jenkins.instance.getQueue() - -print "Queue:\n" -for (job in queue.getItems()) { - def name = job.task.getDisplayName() - if (!name.toLowerCase().contains("tcwg")) { - print "$name}\n" - print " URL: ${job.getUrl()}\n" - // print " Params: ${job.getParams()}\n" - print " Label: ${job.getAssignedLabel()}\n" - print " For: ${job.getInQueueForString()}\n" - print " Since: ${job.getInQueueSince()}\n" - print " Buildable: ${job.isBuildable()}\n" - print " Blocked: ${job.isBlocked()}\n" - print " Stuck: ${job.isStuck()}\n" - print " Why: ${job.getWhy()}\n" - } -} diff --git a/queue.groovy b/queue.groovy index 2a5c796..1a56eea 100644 --- a/queue.groovy +++ b/queue.groovy @@ -1,15 +1,43 @@ +import groovy.json.* + def queue = Jenkins.instance.getQueue() +def json_obj = [:] +def json_jobs = [] + +// Since we can't really do args on command +// line, just add lowercase names you want +// to exclude based on the full display name +// here +// ie: def FILTER = ['tip','tcwg'] +def FILTER = [] -print "Queue:\n" for (job in queue.getItems()) { - print "${job.task.getDisplayName()}\n" - print " URL: ${job.getUrl()}\n" - // print " Params: ${job.getParams()}\n" - print " Label: ${job.getAssignedLabel()}\n" - print " For: ${job.getInQueueForString()}\n" - print " Since: ${job.getInQueueSince()}\n" - print " Buildable: ${job.isBuildable()}\n" - print " Blocked: ${job.isBlocked()}\n" - print " Stuck: ${job.isStuck()}\n" - print " Why: ${job.getWhy()}\n" + name = "${job.task.getFullDisplayName()}" + + if (FILTER.any {name.toLowerCase().contains(it)}) { + continue + } + + // build a map from data of the job.. + def item = [:] + item.put('name', name) + item.put('url', "${job.getUrl()}") + item.put("label", "${job.getAssignedLabel()}") + item.put("for_time", "${job.getInQueueForString()}") + item.put("since", "${job.getInQueueSince()}") + item.put("buildable", "${job.isBuildable()}") + item.put("blocked", "${job.isBlocked()}") + item.put("stuck", "${job.isStuck()}") + item.put("why", "${job.getWhy()}") + + // push it onto a list + json_jobs.add(item) } + +// JsonOutput.toJson() doesn't have a concept of a list +// being the root JSON object, so it will throw stack +// overflow errors unless we give it a map with the list +// as the value. +json_obj.put('jobs', json_jobs) + +JsonOutput.prettyPrint(JsonOutput.toJson(json_obj)) |