简体   繁体   English

Azure 构建列表中的 DevOps 字段值

[英]Azure DevOps Field Values from list of builds

We are using Azure DevOps 2019 on-prem in our firm, and I would like to create an option box field in our Bug work item, and I want it to be a combo-box where the values are builds from all the build definitions under the project.我们在我们公司使用 Azure DevOps 2019 on-prem,我想在我们的 Bug 工作项中创建一个选项框字段,我希望它是一个组合框,其中的值是从下面的所有构建定义构建的该项目。

From checking the documentation of the system, I did not find any option to how to do it, and ether if it would be better to query the System through the API, or Query the DB.通过检查系统的文档,我没有找到如何操作的任何选项,以及是否最好通过 API 查询系统或查询数据库。

I don't think there is a built-in feature like this.我不认为有这样的内置功能。

What you can do, is to create a string field that takes the values from the gloabllist, in the globallist create in the first time a globallist with the project name, for example:您可以做的是创建一个字符串字段,该字段从 gloabllist 中获取值,在 globallist 中首次创建一个带有项目名称的 globallist,例如:

<GLOBALLIST name="MyProject-builds">
</GLOBALLIST>

Now you can use PowerShell to get the build definitions for this project, and update this globallist with the values:现在您可以使用 PowerShell 获取此项目的构建定义,并使用值更新此全局列表:

Param(
   [string]$collection = "http://tfs-server:8080/tfs/collection",
   [string]$project = "MyProject",
   [string]$filePath  = "C:\Globallist.xml"
)

$url = "$collection/$project/_apis/build/definitions?api-version=4.0"
$builds = (Invoke-RestMethod -Uri $url -Method Get -UseDefaultCredentials -ContentType application/json).value.name

witadmin exportgloballist /collection:$collection /f:$filePath
[xml]$gloabllist = Get-Content $filePath
$gloabllist.GLOBALLISTS.GLOBALLIST.Where({ $_.name -eq "$project-builds" }).LISTITEM | %{ $_.ParentNode.RemoveChild($_) | Out-Null }
$node = $gloabllist.GLOBALLISTS.GLOBALLIST.Where({ $_.name -eq "$project-builds" })
$builds.ForEach({

    $child = $gloabllist.CreateElement("LISTITEM")
    $att = $gloabllist.CreateAttribute("value")
    $child.Attributes.Append($att)
    $child.value = "$_"
    $node.AppendChild($child)
})

$gloabllist.Save($filePath)
witadmin importgloballist /collection:$collection /f:$filePath

You can set a scheduled build that tun this script each day to be updated all the time.您可以设置每天调整此脚本的计划构建以始终更新。

You can also improve the script to get all the projects, itreate them, get the build definitions names and update the globallist file.您还可以改进脚本以获取所有项目、迭代它们、获取构建定义名称并更新 globallist 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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