Skip to content

Instantly share code, notes, and snippets.

@dirk-thomas
Created September 30, 2016 20:31
Show Gist options
  • Save dirk-thomas/2bd649852ff07ac283065362dd3d2d7f to your computer and use it in GitHub Desktop.
Save dirk-thomas/2bd649852ff07ac283065362dd3d2d7f to your computer and use it in GitHub Desktop.
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