jenkins python 接口封装
#!/usr/bin/python
#--*-- coding:utf8 --*--
from jenkinsapi.jenkins import Jenkins
import time
class tuan800Jekins(object):
def __init__(self,jobname,url):
self.jobname = jobname
self.url = url
self.server = Jenkins(self.url)
self.job = self.server[self.jobname]
def buildJob(self):
self.server.build_job(self.jobname)
def getJobStatus(self):
if self.job.is_running():
return True
elif self.job.is_queued_or_running():
print 'jon is queue'
else:
return False
def getLastBuildNumber(self):
return self.job.get_last_buildnumber()
def getStatus(self, jobno):
try:
myBuild = self.server[self.jobname].get_build(jobno)
print myBuild.get_status()
except KeyError:
print "Build number: %s is not existed" % jobno
return False
def getBuildTime(self, jobno):
myBuild = self.server[self.jobname].get_build(jobno)
print myBuild.get_timestamp()
def getConsole(self, jobno):
myBuild = self.server[self.jobname].get_build(jobno)
return myBuild.get_console()
if __name__ == '__main__':
a = tuan800Jekins('cart-serv(OK)','Http://192.168.10.168:8080')
b = a.getJobStatus()
print b
#a.buildJob()
time.sleep(10)
e = 'True'
while e:
last_number = a.getLastBuildNumber()
f=a.getConsole(int(last_number))
print f
e=a.getJobStatus()
time = a.getBuildTime(last_number)
result_status = a.getStatus(last_number)
result_dict = {'time': time, 'result_status': result_status, 'lastnumber':last_number}
if result_status == 'SUCCESS':
pass
相关文章