You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 14:03:13