问题
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