0
votes

I am using Azure DevOps (ADO) REST APIs to build dashboards on Power BI. I wanted to query whether the releases pipelines of all projects in my organization have pre-deployment gates of "SonarCloud Quality Gate status" by using the REST APIs invocation.

I have tried this API (Releases - List) GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=5.1. I am reading the MS docs and thought this particular GateStatuswill be useful for my needs, but this GateStatus does not show up when I am testing on my pipelines that have pre-deployment gates of "SonarCloud Quality Gate status" configured.

I found this API (Release - Get Release) GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=5.1 with MS docs. That preDeploymentGates shows the information I want when I am testing in POSTMAN. But, the problem is it requires releaseId in each query which is troublesome for me since my ultimate goal is to have a list of ALL releases in multiple projects of multiple organizations.

Thanks.

1

1 Answers

0
votes

since my ultimate goal is to have a list of ALL releases in multiple projects of multiple organizations.

Since you want to get the Pipelines pre-deployment gates status for ALL releases in multiple projects of multiple organizations, so we use the API (Release - Get Release) to get the gates status, then loop this API in the all Release pipelines in one project, next, loop the all projects in one ORG, latest, loop all ORGs.

First, We need to create a All accessible organization PAT:

enter image description here

Because we need access multiple organizations.

Second, set a array to store the multiple organization names:

$ORGNames=@("Organization1","Organization2")

Then using following powershell scripts to loop the API (Release - Get Release):

$connectionToken="PAT"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))

$ORGNames=@("Organization1","Organization2")


ForEach ($ORGName in $ORGNames[0,1])

{

$ProjectUrl = "https://dev.azure.com/$($ORGName)/_apis/projects?api-version=5.1" 

Write-Host "URL: $ProjectUrl"

$Projects = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})

$ProjectId = $projects.value.id


Write-Host "Projects = $ProjectId"



    ForEach ($Pt in $ProjectId)

    {

    $baseUrl = "https://vsrm.dev.azure.com/$($ORGName)/$($Pt)/_apis/release/releases?api-version=5.1"                   
    $ReleaseId = (Invoke-RestMethod -Uri $baseUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
    $ReleaseIds = $ReleaseId.value.id

    Write-Host "ReleaseID = $ReleaseId"



        foreach($ReleaseID in $ReleaseIds){

        $url = "https://vsrm.dev.azure.com/$($ORGName)/$($Pt)/_apis/release/releases/$($ReleaseID)?api-version=5.1"

        $GatesStatus = (Invoke-RestMethod -Uri $url -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})

        Write-Host "GatesStatus For ORGName $ORGName Project $Pt And Release ID $ReleaseID= $($GatesStatus.environments.deploySteps.preDeploymentGates.status | ConvertTo-Json -Depth 100)"

         }
      }

   }

The test result:

enter image description here

Hope this helps.