如何通过TeamCity REST API获取TestOccurrence的输出?
获取TeamCity测试输出(stdout)的REST API方法
操作步骤
第一步:获取目标测试的TestOccurrence信息
调用TestOccurrence定位接口,拿到测试的id和logAnchor字段:GET http://<teamcity-server地址>/app/rest/testOccurrences?locator=build:<构建ID>,testName:<测试名称>从返回的JSON数据里提取
id(即测试实例ID)和logAnchor的具体值。第二步:调用日志获取接口
使用API凭证发起请求,替换<测试实例ID>和<logAnchor值>:GET http://<teamcity-server地址>/app/rest/testOccurrences/<测试实例ID>/log?anchor=<logAnchor值>该接口会直接返回测试的完整stdout(也就是Web UI里显示的"stacktrace"内容)。
权限与认证说明
- 确保你的API凭证(令牌或用户名+密码)拥有查看构建结果的权限
- 认证方式:
- 令牌认证:请求头添加
Authorization: Bearer <你的令牌> - 用户名密码认证:使用HTTP Basic Auth
- 令牌认证:请求头添加
兼容提示
如果上述接口返回404,可尝试在路径中加入internal,部分TeamCity版本需要这个前缀:
GET http://<teamcity-server地址>/app/rest/internal/testOccurrences/<测试实例ID>/log?anchor=<logAnchor值>
内容的提问来源于stack exchange,提问作者dcrosta
相关产品推荐
相关产品推荐

