生成失败时在其他项目中创建错误 [英] Create bug in a different project when build fails

查看:62
本文介绍了生成失败时在其他项目中创建错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经建立了一个构建定义,该定义将创建一个错误,并将其分配给请求者",以防构建失败.参见下文:

We have setup a build definition which creates a bug and assigns it to "requestor" incase the build fails. See below :

默认情况下,错误是在同一项目中创建的.如何更改此设置以在其他项目中创建错误?原因是,我们的工作项跟踪与Git仓库位于不同的项目中(由于改组而未进行改组).请注意,这两个项目都在同一个帐户下.

By default, the bugs are created in the same project. How do I change this to create the bugs in a different project ? The reason is, our work item tracking is in a different project than our Git repos (due to reshuffling and what not). Note that both the projects are under the same account.

看一下工具提示,它提供了一些示例字段,是否有对应于项目"的字段? (System.Project吗?!)

Looking at the tool tip, it provides some sample fields, is there a corresponding field for "project" ? (System.Project ?!)

推荐答案

VSTS构建中的失败时创建工作项"选项只能在同一项目中创建工作项.

The Create work item on failure option in VSTS build can only create work item in the same project.

可以通过添加PowerShell任务来实现在构建失败时创建Bug的解决方法.详细步骤如下:

The workaround to create a Bug if build failed can be achieved by adding a PowerShell task. Detail steps as below:

在PowerShell脚本中,可以通过

In the PowerShell script, you can create a Bug for a different project by REST API. Below is an example script:

$witType="Bug"
$witTitle="Build $(build.buildNumber) failed"


$u="https://account.visualstudio.com/DefaultCollection/project/_apis/wit/workitems/`$$($witType)?api-version=1.0"
$body="[
          {
            `"op`": `"add`",
            `"path`": `"/fields/System.Title`",
            `"value`": `"$($witTitle)`"
          }
       ]"
$user = "user"
$token = "PAT"

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$result=Invoke-RestMethod -Method PATCH -Uri $u -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType "application/json-patch+json" -Body $body

2.将运行此任务"选项指定为即使先前的任务失败,除非构建被取消

从第二个任务到最终任务(PowerShell任务),将运行此任务"选项更改为即使上一个任务失败,除非构建被取消:

因此,当构建失败时,将在PowerShell脚本中指定的其他项目中创建错误.

So when build fails, a Bug will be create to the different project as you specified in PowerShell script.

这篇关于生成失败时在其他项目中创建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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