我正在尝试使用'jenkins api'和'python'打印'Jenkins'的工作细节
我可以打印'Jenkins版'但不能打印Jenkins的'job_details'
from jenkinsapi.jenkins import Jenkins
if __name__ == '__main__':
jenkins_url = 'https://dev.localhost.com/XXXX/jenkins/'
server = Jenkins(jenkins_url, 'user', 'password')
print server.version
print server.get_jobs()
输出
2.32
<generator object iteritems at 0x7f4a46220fa0>
我的代码(或)有什么问题我应该做别的吗?
按建议添加了StackTrace
Traceback (most recent call last):
File "jenver.py", line 26, in <module>
for job in jobs:
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi/jobs.py", line 91, in iteritems
for job in self.itervalues():
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi/jobs.py", line 116, in itervalues
yield Job(row['url'], row['name'], self.jenkins)
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi/job.py", line 74, in __init__
JenkinsBase.__init__(self, self.url)
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi/jenkinsbase.py", line 35, in __init__
self.poll()
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi/job.py", line 98, in poll
data = super(Job, self).poll(tree=tree)
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi/jenkinsbase.py", line 59, in poll
data = self._poll(tree=tree)
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi/jenkinsbase.py", line 69, in _poll
return self.get_data(url, tree=tree)
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi/jenkinsbase.py", line 79, in get_data
response = requester.get_url(url, params)
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi/utils/requester.py", line 109, in get_url
return requests.get(self._update_url_scheme(url), **requestKwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 487, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='6.4.2.182', port=8080): Max retries exceeded with url: /scm/jenkins/job/DO%20NOT%20CHANGE%20THIS%20PROJECT/api/python (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f5bcf894150>: Failed to establish a new connection: [Errno 110] Connection timed out',))
答案 0 :(得分:0)
问题是get_jobs
正在返回生成器而不是列表。有关如何打印作业的详细信息,请参阅example 2.
要打印生成器的项目,请尝试执行以下操作:
from jenkinsapi.jenkins import Jenkins
if __name__ == '__main__':
jenkins_url = 'https://dev.localhost.com/XXXX/jenkins/'
server = Jenkins(jenkins_url, 'user', 'password')
jobs = server.get_jobs()
for job in jobs:
print(job)