How to get all build variables and values with vNext Build in Azure DevOps 2019?

无人久伴 提交于 2021-01-29 07:49:46

问题


Recently, we have upgraded our build server into Azure DevOps 2019 and there are some legacy builds.

Instead of go through each variable one by one and manually check the value.

Are we able to directly pull all of them together in a script?


回答1:


Instead of complicated script, you could just simply use a single cmd.exe command /k set to achieve your requirement.

It will print all of your build variables include customized and system even build agent variable info alphabetically.




回答2:


You can use TFS Rest API to fetch all the build denifions data and print the variables.

A PowerShell script that does it:

$url = "http://tfs-server:8080/tfs/collection/team-project/_apis/build/definitions?api-version=4.0&includeAllProperties=true"

$builds = Invoke-RestMethod -Method Get -Uri $url -UseDefaultCredentials

ForEach($build in $builds.value)

{

    Write-Host "$($build.name)" -ForegroundColor Yellow

    $objMembers = $build.variables.psobject.Properties

    foreach ($member in $objMembers)

    {

        Write-Host "Variable Name: $($Member.Name)"

        Write-Host "Value: $($Member.Value.value)"

    }

    Write-Host "`n"

}


来源:https://stackoverflow.com/questions/58320689/how-to-get-all-build-variables-and-values-with-vnext-build-in-azure-devops-2019

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!