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
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341