我使用python jenkins包装器从python对jenkins进行操作。我想使用server.delete_build
命令删除生成,但每当我尝试使用此命令时:
import jenkins
def build_job(para_value):
server = jenkins.Jenkins('http://localhost:8080', username='username', password='password')
if not server.job_exists('job_name'):
server.create_job('job_name', jenkins.EMPTY_CONFIG_XML)
server.build_job('job_name', parameters={'para1': para_value})
def delete_build(jobID):
print(jobID)
server = jenkins.Jenkins('http://localhost:8080', username='username', password='password')
server.delete_build('job_name', jobID)
这是我得到的错误:
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py", line 1415, in delete_build
self.jenkins_open(requests.Request('POST',
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py", line 557, in jenkins_open
return self.jenkins_request(req, add_crumb, resolve_auth).text
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py", line 573, in jenkins_request
self.maybe_add_crumb(req)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py", line 379, in maybe_add_crumb
req.headers[self.crumb['crumbRequestField']] = self.crumb['crumb']
有人能提出解决办法吗
关于这个错误没有太多的信息或解决方案,所以我在Jenkins模块的
__init__.py
中更改了if条件。 转到/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/jenkins/__init__.py
(此地址适用于Mac用户):这样做:
删除:
if self.crumb:
添加:
if self.crumb and isinstance(req.headers, dict):
这将使您的代码正常工作
这个答案的灵感来自:https://www.mail-archive.com/python-jenkins-developers@lists.launchpad.net/msg00597.html
相关问题 更多 >
编程相关推荐