-
Notifications
You must be signed in to change notification settings - Fork 0
/
SST1.py
52 lines (41 loc) · 1.34 KB
/
SST1.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sqlite3
import datetime
#python-jenkins wrapper
import jenkins
import json
import sys
import urllib
import urllib2
jenkinsUrl = "localhost:8080/job"
def getjobstatus(jobname):
try:
jenkinsStream = urllib2.urlopen(jenkinsUrl + jobName + "/lastBuild/api/json")
except urllib2.HTTPError, e:
print "URL Error: " + str(e.code)
print " (job name [" + jobName + "] probably wrong)"
return
try:
buildStatusJson = json.load(jenkinsStream)
except:
print "Failed to parse json"
return
if buildStatusJson.has_key("result"):
print "[" + jobName + "] build status: " + buildStatusJson["result"]
return buildStatusJson["result"]
db = sqlite3.connect(':memory:')
cursor = db.cursor()
cursor.execute('''
CREATE TABLE jobs(id INTEGER PRIMARY KEY, status TEXT,
time TIMESTAMP )
''')
db.commit()
server = jenkins.Jenkins('http://localhost:8080', username='admin', password='53c00a069a0047f0a092cdb1d586728e')
jobs = server.get_jobs()
for job in jobs:
jobName = job['name']
jobStatus = getjobstatus(jobName)
dateNow = datetime.datetime.now()
cursor = db.cursor()
cursor.execute('''INSERT INTO jobs(status, time)
VALUES(?,?)''', (jobStatus, dateNow))
db.close()