Search code examples
tfsazure-devopstfs-workitemazure-devops-server-2019azure-devops-server

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.

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.


Solution

  • 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:

    <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:

    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.