当 Visual Studio 测试任务出现此类警告时,您可以使用其他方式使构建结果失败。详细步骤如下:
1.在 Visual Studio 测试任务之后添加 PowerShell 任务。
2。然后通过Timeline获取Visual Studio Test任务构建信息:
GET https://account.visualstudio.com/DefaultCollection/{project}/_apis/build/builds/{buildID}/timeline?api-version=2.0
buildID可以通过预定义变量$(Build.BuildId)获取。
3。按任务名称或任务显示名称搜索 Visual Studio 测试任务信息。
比如rest api的部分响应如下:
{
"id": "59863cf3-dc46-4e1b-914a-6e903e1aa924",
"parentId": "95930a52-e560-42d6-b9d2-14e0eef98758",
"type": "Task",
"name": "VsTest - testAssemblies",
"startTime": "2017-10-03T15:54:36.35Z",
"finishTime": "2017-10-03T15:54:37.897Z",
"currentOperation": null,
"percentComplete": null,
"state": "completed",
"result": "succeeded",
"resultCode": null,
"changeId": 16,
"lastModified": "0001-01-01T00:00:00",
"workerName": "Hosted Agent",
"order": 5,
"details": null,
"errorCount": 0,
"warningCount": 2,
"url": null,
"log": {
"id": 6,
"type": "Container",
"url": "https://maaccount.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/1583/logs/6"
},
"task": {
"id": "ef087383-ee5e-42c7-9a53-ab56c98420f9",
"name": "VSTest",
"version": "2.1.12"
},
"issues": [
{
"type": "warning",
"category": "General",
"message": "",
"data": {
"type": "warning",
"code": "002004"
}
},
{
"type": "warning",
"category": "General",
"message": "No test assemblies found matching the pattern: **\\*test*.dll,!**\\obj\\**.",
"data": {
"type": "warning"
}
}
]
}
您可以按任务名称VSTest或任务显示名称VsTest - testAssemblies进行搜索。
对于issues 对象,您可以获得所需的警告。
4.如果 VS 测试有您指定的警告,则构建结果失败。
如果有您指定的警告(例如警告No test assemblies found matching the pattern: **\DBX.Tests*.dll;-:**\obj\**),您可以通过
使PowerShell任务失败
exit 1