我有一個Jenkins的工作,名字是Test2
,我可以從Jenkins的web界面創建。現在我想用JenkinsAPI觸發該構建。我只能找到示例代碼來執行其他操作,但API Documentation提到了Build
類。所以我想我會嘗試實例化它,然後等待它完成(希望這也會觸發實際的構建),但是我比那更早得到相當神祕的錯誤。我究竟做錯了什麼?如何使用Python包JenkinsAPI觸發Jenkins構建?
import jenkinsapi
b = jenkinsapi.build.Build("http://localhost:8080", 1, "test2")
b.block_until_complete()
給我:
Traceback (most recent call last):
File "/Users/jonathan/Genetta/Eclipse_Django_workspace/FOO/foo/TriggerBuild.py", line 2, in <module>
b = jenkinsapi.build.Build("http://localhost:8080", 1, "test2")
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/jenkinsapi/build.py", line 58, in __init__
JenkinsBase.__init__(self, url)
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.py", line 35, in __init__
self.poll()
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.py", line 59, in poll
data = self._poll(tree=tree)
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/jenkinsapi/build.py", line 65, in _poll
return self.get_data(url, params={'depth': self.depth}, tree=tree)
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/jenkinsapi/jenkinsbase.py", line 72, in get_data
requester = self.get_jenkins_obj().requester
File "/Users/jonathan/anaconda/lib/python2.7/site-packages/jenkinsapi/build.py", line 371, in get_jenkins_obj
return self.job.get_jenkins_obj()
AttributeError: 'str' object has no attribute 'get_jenkins_obj'