简体   繁体   中英

How to add a related work item when the build pipeline fails in Azure DevOps?

I'm trying to set up my build pipeline in a way that, if it fails for some reason, then creates a new work item. However, is it possible to add a related work item for these automatically created work items?

构建管道选项

Right now, I'm manually adding a related user story just to keep my azure board organized and clean, and I have a guess that this related work is also an additional field, but couldn't find which of these fields should I use and how to use them in the options tab.

This is the desired result that I'm looking for:

相关工作项

I found this question that have a similar problem that I have, just missing this step on how to add related work item.

is it possible to add a related work item for these automatically created work items?

I am afraid that the Create work item on failure option in Pipeline option doesn't support adding a related work item for newly created work items.

It only supports defining the field of work items. But the Parent work item link belongs to relations .

Since you don't want to use the Rest API, I suggest that you could use the Create Work Item task from Create Work Item extension.

Then you could directly add this task at the end of your agent job.

For example:

在此处输入图像描述

In this task, you could define the related work item:

在此处输入图像描述

Then you could set the condition in the task(eg Only when a previous task has failed).

在此处输入图像描述

In this case, when the pipeline fails, it will run task and create a work (contain parent work item link).

As of this time, however, adding parent work item directly for created work items in "Create work item on failure" is not currently supported, because the information about related work items is not stored in fields, but in relations.

As an alternative method, you can create a work item and set parent for it by REST API Work Items - Create .

POST https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/${type}?api-version=6.0

Here is an example:

[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "SampleTask"
  },
  {
    "op": "add",
    "path": "/relations/-",
    "value": {
      "rel": "System.LinkTypes.Hierarchy-Reverse",
      "url": "https://dev.azure.com/{organization}/{project}/_apis/wit/workItems/{parent work item id}"
    }
  }
]

The second paragraph is used to add parent.

Details on how to run the REST API in your pipeline can be found in your linked questions .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM