Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Collect number of builds and accumulated duration on Jenkins
#!/usr/bin/env python3
import os
import re
start = 1472688000
end = 1475280000
build_count = 0
sum_duration = 0
for job_name in os.listdir():
builds_path = os.path.join(job_name, 'builds')
if not os.path.isdir(builds_path):
continue
for build_name in os.listdir(builds_path):
build_path = os.path.join(builds_path, build_name)
if os.path.islink(build_path) or not os.path.isdir(build_path):
continue
mtime = float(os.path.getmtime(build_path))
if mtime < start or mtime >= end:
continue
build_count += 1
build_xml_path = os.path.join(build_path, 'build.xml')
if not os.path.exists(build_xml_path):
continue
with open(build_xml_path, 'r') as h:
content = h.read()
m = re.search('<duration>(.+)</duration>', content)
if not m:
print(build_xml_path)
exit(1)
sum_duration += int(m.group(1)) / 1000
print('%d builds' % build_count)
print('%d hours' % (sum_duration / 60 / 60))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment