-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_jenkins_build_logs.py
35 lines (35 loc) · 1.25 KB
/
parse_jenkins_build_logs.py
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
#!/usr/bin/python
from hashlib import sha1
import os , re , sys , json
import xml.etree.ElementTree as ET
from es_utils import send_payload
path = '/build/jobs'
index = "jenkins"
document = "builds-data"
rematch = re.compile(".*/builds/\d+$")
for root, dirs, files in os.walk(path):
if rematch.match(root):
logFile = root + '/build.xml'
flagFile = root + '/check.done'
if os.path.exists(logFile) and not os.path.exists(flagFile):
payload = {}
job_info = root.split('/')
payload['job_name'] = job_info[3]
payload['build_number'] = job_info[-1]
id = sha1(root).hexdigest()
try:
tree = ET.parse(logFile)
root = tree.getroot()
payload['start_time'] = root.find('startTime').text
payload['slave_node'] = root.find('builtOn').text
build_result = root.find('result')
if build_result is not None:
payload['build_result'] = build_result.text
payload['build_duration'] = int(int(root.find('duration').text)/1000)
payload['job_status'] = 'Finished'
os.system('touch ' + flagFile)
else:
payload['job_status'] = 'Running'
send_payload(index,document,id,json.dumps(payload))
except Exception as e:
print "Xml parsing error" , e