【问题标题】:Is there a REST API to get the build errors in Azure DevOps?是否有 REST API 来获取 Azure DevOps 中的构建错误?
【发布时间】:2019-10-03 00:01:56
【问题描述】:
所以,这就是我所知道的:
- 我可以获取构建数据,在那里我可以找到带有 url 的
logs 属性。
- 访问日志 url 会返回一个链接数组,这些链接指向构建日志的各个部分(可能是每个构建任务的一部分,按照构建定义中后者的顺序)
- 每个部分中的 url 都为我提供了相应任务记录的文本。
- 我可以解析它,所有匹配
##[error] 的内容都对应于构建摘要页面上记录的错误。
如果我只需要获取构建错误,我很好奇这是否是最好的方法。我不需要整个日志。
【问题讨论】:
标签:
azure-devops
azure-devops-rest-api
【解决方案1】:
如果有错误,您也可以使用Build Timeline API 并在那里检查结果。
API 响应包含属性issues,因此只需检查它是否不为空并打印问题消息。
例如(在 PowerShell 中):
# Get here the response from the api
$response = Invoke-RestMethod ......
$errors = $response.records.Where({ $_.issues -ne $null })
$errors.ForEach({
# Task name
$_.name
# Error message
$_.issues.ForEach({ $_.message })
})