Jenkins Python Interface Encapsulation

Source: Internet
Author: User

#!/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


This article is from the "Expect batch Sync data" blog, so be sure to keep this source http://4249964.blog.51cto.com/4239964/1608893

Jenkins Python Interface Encapsulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.