是否有 REST API 来获取 Azure DevOps 中的构建错误?
Is there a REST API to get the build errors in Azure DevOps?
所以,这是我所知道的:
- 我可以获得构建数据,在那里我可以找到带有 url.
的 logs
属性
- 访问日志 url returns 构建日志各个部分的链接数组(大概是每个构建任务的一部分,按照构建定义中后者的顺序)
- 每个部分的 url 获取相应任务记录的文本。
- 我可以解析它,所有匹配
##[error]
的内容都对应于构建摘要页面上记录的错误。
我很好奇如果我只需要获取构建错误,这是否是最好的方法。我不需要整个日志。
您也可以使用 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 })
})
所以,这是我所知道的:
- 我可以获得构建数据,在那里我可以找到带有 url. 的
- 访问日志 url returns 构建日志各个部分的链接数组(大概是每个构建任务的一部分,按照构建定义中后者的顺序)
- 每个部分的 url 获取相应任务记录的文本。
- 我可以解析它,所有匹配
##[error]
的内容都对应于构建摘要页面上记录的错误。
logs
属性
我很好奇如果我只需要获取构建错误,这是否是最好的方法。我不需要整个日志。
您也可以使用 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 })
})