-
Notifications
You must be signed in to change notification settings - Fork 1
/
getJenkinsHistory.py
executable file
·55 lines (45 loc) · 1.75 KB
/
getJenkinsHistory.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
53
54
55
#!/bin/python2.7
from jenkinsapi.jenkins import Jenkins
import os
from traceback import format_exc
url_get_all_builds = "http://18.222.147.201:8080//job/{}/api/json?tree=allBuilds[*]&depth=2"
version_base = "1.0.0"
def get_server_instance():
server = Jenkins(jenkins_url, username = 'kasema', password = 'admin')
return server
def getSCMInfroFromLatestGoodBuild(url, jobName, tags, username=None, password=None):
specific_url = url_get_all_builds.format(jobName)
j = Jenkins(url, username, password)
job = j[jobName]
lgb = job.get_last_good_build()
last_build_number = job.get_last_buildnumber()
last_build_tag = tags[-1]
#new_tag = (int(''.join(last_build_tag.split('.'))) + 1)
# lf = open('/home/ec2-user/workspace/piplineJob/logfile.log', 'w')
if not last_build_number:
return
for i in range(last_build_number, 0, -1):
try:
build = job.get_build(i)
print build.get_timestamp()
# lf.write('{}'.format(build.get_timestamp()))
# lf.write('\n')
print build.get_timestamp()
except KeyError:
break
if __name__ == '__main__':
# lf = open('/home/ec2-user/workspace/piplineJob/logfile.log', 'w')
# try:
#job_name = 'testing'
job_name = 'testing'#os.environ['JOB_NAME']
username = 'kasema'#os.environ['JENKINS_USERNAME']
password = 'admin'#os.environ['JENKINS_PASSWORD']
jenkins_url = "http://18.222.147.201:8080"#os.environ['JENKINS_URL']
tags = os.environ['BUILD_TAG']
getSCMInfroFromLatestGoodBuild(jenkins_url, job_name, tags, username, password)
# except:
# lf.write(format_exc())
# lf.write('\n')
# finally:
# lf.flush()
# lf.close()