Skip to content

Instantly share code, notes, and snippets.

@fisshy
Last active September 14, 2023 06:14
Show Gist options
  • Save fisshy/4c54f116ee1e9d0c23c03b5419e32757 to your computer and use it in GitHub Desktop.
Save fisshy/4c54f116ee1e9d0c23c03b5419e32757 to your computer and use it in GitHub Desktop.
List all defined variables for all release pipelines in azure devops
Get-Content "auth.config" | foreach-object -begin {$h=@{}} -process {
$k = [regex]::split($_,'=');
if(($k[0].CompareTo("") -ne 0) -and ($k[0].StartsWith("[") -ne $True)) {
$h.Add($k[0], $k[1])
}
}
$username = $h.Get_Item("Username")
$password = $h.Get_Item("Password")
$apiVersion = "6.0"
$organization = "X"
$project = "X"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$headers = @{
"Authorization" = ("Basic {0}" -f $base64AuthInfo)
"Accept" = "application/json"
}
$response = Invoke-RestMethod -Uri "https://vsrm.dev.azure.com/$organization/$project/_apis/release/definitions?api-version=$apiVersion" -Headers $headers -Method Get
$releaseDefinitions = $response.value
$releaseDefinitions | ForEach-Object {
$url = "https://vsrm.dev.azure.com/$organization/$project/_apis/release/definitions/$($_.id)?api-version=$apiVersion"
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
$environments = $response.environments
foreach ($environment in $environments) {
foreach($obj in $environment.variables.PSObject.Properties) {
Write-Host $obj.Name, $obj.Value.value
}
}
$variables = $response.variables
foreach ($obj in $variables.PSObject.Properties) {
Write-Host $obj.Name, $obj.Value.value
}
}
[General]
Username=xx@xx.se
Password=YOUR_PERSONAL_ACCESS_TOKEN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment