1

My code is given below

from jenkinsapi.jenkins import Jenkins

def get_server_instance():
    jenkins_url = 'https://<privateJenkinsServer>:<port>'
    print "Hello" 
   server = Jenkins(jenkins_url, username = 'foouser', password = 'foopassword')
    return server

if __name__ == '__main__':
    print get_server_instance().version

When I execute this, it just prints "Hello" and then hangs. What could be the reason for this ?

N.B. I am running this in my corporate network behind a proxy.

Reference: http://pythonhosted.org/jenkinsapi/using_jenkinsapi.html#example-1-get-version-of-jenkins

When I killed the command, I get the following error.

File "C:\Python27\lib\ssl.py", line 643, in read
    v = self._sslobj.read(len)

Complete log.

>>> execfile('C:\Users\idatta\Project\Python\Demo\JenkinsAPI_v1.py')
started
https://jenkm1.discoverfinancial.com:8443

Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    execfile('C:\Users\idatta\Project\Python\Demo\JenkinsAPI_v1.py')
  File "C:\Users\idatta\Project\Python\Demo\JenkinsAPI_v1.py", line 28, in <module>
    print get_server_instance().version
  File "C:\Users\idatta\Project\Python\Demo\JenkinsAPI_v1.py", line 19, in get_server_instance
    server = Jenkins(jenkins_url, username = 'idatta', password = 'Gr33nCard_1', ssl_verify=False)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkins.py", line 59, in __init__
    JenkinsBase.__init__(self, baseurl, poll=not lazy)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 35, in __init__
    self.poll()
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 61, in poll
    data['jobs'] = self.resolve_job_folders(data['jobs'])
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 100, in resolve_job_folders
    jobs += self.process_job_folder(job, self.baseurl)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 112, in process_job_folder
    result += self.process_job_folder(job, folder_path)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 112, in process_job_folder
    result += self.process_job_folder(job, folder_path)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 107, in process_job_folder
    tree='jobs[name,color]')
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 79, in get_data
    response = requester.get_url(url, params)
  File "C:\Python27\lib\site-packages\jenkinsapi\utils\requester.py", line 109, in get_url
    return requests.get(self._update_url_scheme(url), **requestKwargs)
  File "C:\Python27\lib\site-packages\requests\api.py", line 70, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python27\lib\site-packages\requests\api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 423, in send
    timeout=timeout
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 594, in urlopen
    chunked=chunked)
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 384, in _make_request
    httplib_response = conn.getresponse(buffering=True)
  File "C:\Python27\lib\httplib.py", line 1136, in getresponse
    response.begin()
  File "C:\Python27\lib\httplib.py", line 453, in begin
    version, status, reason = self._read_status()
  File "C:\Python27\lib\httplib.py", line 409, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "C:\Python27\lib\socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
  File "C:\Python27\lib\ssl.py", line 756, in recv
    return self.read(buflen)
  File "C:\Python27\lib\ssl.py", line 643, in read
    v = self._sslobj.read(len)
KeyboardInterrupt
>>> 
4

1 回答 1

2

上的错误v = self._sslobj.read(len)意味着您在读取过程中被打断。它似乎完全没有文档记录,但是 jenkinsapi 会尝试在每项工作开始时下载有关它的信息,如果您的 Jenkins 存储库很大,那将需要很长时间。可以设置lazy=True,但当您尝试访问单个作业时,它仍会尝试加载所有作业。使用其他库可能更好。

server = Jenkins(jenkins_url, username = 'foouser', password = 'foopassword', lazy=True)
于 2017-08-25T08:20:36.427 回答