在TeamCity 9.x Documentation的Triggering a Build
部分有一个旋度示例:
curl -v -u user:password http://teamcity.server.url:8111/app/rest/buildQueue --request POST --header "Content-Type:application/xml" --data-binary @build.xml
我想知道如何将它转换成等效的Python脚本(使用来自requests
模块的POST
请求)?在
顺便说一句,我尝试了下面的Python脚本,但是得到了这样一个响应代码400 (Bad Request)
:
url = "http://myteamcity.com:8111/httpAuth/app/rest/buildQueue/"
headers = {'Content-Type': 'application/json'}
data = json.dumps({'buildTypeId': 'MyTestBuild'})
r = requests.post(url, headers=headers, data=data, auth=("username", "password"), timeout=10)
print "r = ", r
>> r = <Response [400]>
如果将headers
中的Content-Type
更改为Accept
,则得到另一个响应代码415 (Unsupported Media Type)
:
FYI json请求适用于TeamCity 10。在
触发构建的文档显示您需要发送XML,而不是JSON:
teamcityrestapi有点复杂;有些方法同时接受XML和JSON,有些只接受XML。这是后一种方法。它们将根据您设置的
Accept
报头来响应XML或JSON。在将上面的内容与所需的构建ID一起发送;对于只需使用模板的XML文档:
^{pr2}$注意,我使用了^{} function 来确保
build_id
的值被正确地引用为XML属性。在这将生成XML;如果要处理JSON响应,请将
'Accept': 'application/json'
添加到headers
字典中。在相关问题 更多 >
编程相关推荐