如何获取vsts CI构建中先前任务失败的原因 [英] How to get reason for failure of a previous task in vsts CI build

查看:106
本文介绍了如何获取vsts CI构建中先前任务失败的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以获取上一个任务失败的原因,因此我可以在下一个任务中使用它.现在,我正在命名和羞辱谁破坏了构建并将其链接到以松弛方式完成的提交.但是除非您去vsts并查看日志,否则您无法说出它为什么崩溃了.

Is there a way to get the reason for a previous task failing so I can use it in a later task. Right now I'm naming and shaming who ever breaks the build and linking to the commit that did it in slack. But you can't tell why it broke unless you go to vsts and look at the logs.

我没有看到任何 build 变量做好失败准备.现在,我唯一想到的就是将stderr路由到文件和控制台,然后在失败时将该文件读入变量.但这似乎很骇人.

I didn't see any build variables that get set on failures. Right now the only thing I can think of is to route stderr to a file and the console and then on failure read that file into a variable. But that seems hacky.

推荐答案

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

After the task which you want to get the detail failed reason, you can add a PowerShell task to get the previous tasks’ details by Rest API. Detail steps in the PowerShell task:

1..执行

1. Execute the rest API to get all the previous build tasks’ details.

2..按任务name搜索失败的任务或构建result.您可以通过

2. Search the failed task by task name or build result. An you can get the task’s detail as

{
  "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..然后,您可以在 url选项中获取详细信息失败日志(作为 网址 https://account.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/1339/logs/3 在上述示例中).

3. Then you can get the detail failed logs in the url option (as the url https://account.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/1339/logs/3 in above example).

这篇关于如何获取vsts CI构建中先前任务失败的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆