簡體   English   中英

Azure 構建列表中的 DevOps 字段值

[英]Azure DevOps Field Values from list of builds

我們在我們公司使用 Azure DevOps 2019 on-prem,我想在我們的 Bug 工作項中創建一個選項框字段,我希望它是一個組合框,其中的值是從下面的所有構建定義構建的該項目。

通過檢查系統的文檔,我沒有找到如何操作的任何選項,以及是否最好通過 API 查詢系統或查詢數據庫。

我不認為有這樣的內置功能。

您可以做的是創建一個字符串字段,該字段從 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 文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM