构建失败时在不同的项目中创建错误 [英] Create bug in a different project when build fails

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

问题描述

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

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

看工具提示,它提供了一些示例字段,项目"是否有相应的字段?(系统项目?!)

解决方案

VSTS build 中的 Create work item on failure 选项只能在同一个项目中创建工作项.

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

1.在构建定义的末尾添加一个 PowerShell

在PowerShell脚本中,您可以通过

因此,当构建失败时,将会为您在 PowerShell 脚本中指定的不同项目创建一个错误.

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

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.

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

解决方案

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

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

1. Add a PowerShell in the end of your build definition

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. Specify Run this task option as Even if a previous task has failed, unless the build was canceled

From Second task to the end task (PowerShell task), change Run this task option as Even if a previous task has failed, unless the build was canceled:

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

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

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