0

我们在公司内部使用 Azure DevOps 2019,我想在我们的 Bug 工作项中创建一个选项框字段,我希望它是一个组合框,其中的值是从下面的所有构建定义构建的该项目。

通过检查系统的文档,我没有找到任何选项来执行此操作,以及是否通过 API 查询系统或查询数据库更好。

4

1 回答 1

1

我不认为有这样的内置功能。

您可以做的是创建一个字符串字段,该字段从 gloabllist 中获取值,在 globallist 中首次创建一个带有项目名称的 globallist,例如:

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

现在您可以使用 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

您可以设置每天调整此脚本的计划构建以始终更新。

您还可以改进脚本以获取所有项目、迭代它们、获取构建定义名称并更新 globallist 文件。

于 2019-09-24T09:10:42.950 回答