如何在vsts CI构建中获取先前任务失败的原因

时间:2017-08-25 20:57:22

标签: azure-devops

有没有办法让上一个任务失败的原因让我可以在以后的任务中使用它。现在,我正在命名和羞辱那些破坏构建并链接到松弛的提交。但除非你去看看并查看日志,否则你无法告诉它为什么会破坏。

我没有看到任何在失败时设置的build变量。现在我唯一能想到的是将stderr路由到文件和控制台,然后在失败时将该文件读入变量。但这看起来很糟糕。

1 个答案:

答案 0 :(得分:1)

在您要获取详细信息失败原因的任务之后,您可以添加 PowerShell任务以通过Rest API获取先前任务的详细信息。 PowerShell任务中的详细步骤:

1。执行rest API以获取所有以前的构建任务的详细信息。

2。按任务name或构建result搜索失败的任务。您可以将任务的详细信息视为

{
  "id": "b75e0dd2-9734-4e83-ab5b-dc6001ea037c",
  "parentId": "78e591b0-98f5-4d8a-a46c-417fda2c36dc",
  "type": "Task",
  "name": "Run cd ",
  "startTime": "2017-08-28T05:33:51.86Z",
  "finishTime": "2017-08-28T05:33:53.053Z",
  "currentOperation": null,
  "percentComplete": null,
  "state": "completed",
  "result": "failed",
  "resultCode": null,
  "changeId": 12,
  "lastModified": "0001-01-01T00:00:00",
  "workerName": "machine",
  "order": 4,
  "details": null,
  "errorCount": 1,
  "warningCount": 0,
  "url": null,
  "log": {
    "id": 3,
    "type": "Container",
    "url": "https://account.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/1339/logs/3"
  }

3. 然后您可以在网址选项中获取详细的失败日志(作为  以上示例中的网址https://account.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/1339/logs/3