Last active
July 5, 2022 02:04
-
-
Save glombard/f856659f604593b535c2 to your computer and use it in GitHub Desktop.
Plot a graph of Jenkins job build durations over time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import datetime | |
import time | |
from dateutil import tz | |
import matplotlib.pyplot as plt | |
import pytz | |
import requests | |
logging.captureWarnings(True) | |
def get_timestamp(ts): | |
t = datetime.datetime(*time.gmtime(ts / 1000.0)[:6]) | |
return pytz.utc.localize(t).astimezone(tz.tzlocal()) | |
url = 'https://my-jenkins/job/my-job/api/json?tree=allBuilds[timestamp,duration]' | |
response = requests.get(url) | |
data = response.json() | |
builds = data['allBuilds'] | |
x = [get_timestamp(e['timestamp']) for e in builds] | |
y = [e['duration'] / 60000 for e in builds] | |
plt.plot(x, y) | |
plt.gcf().autofmt_xdate() | |
plt.show() |
Works like a charm :) Thank you for sharing!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The result might look something like: