Sitemap

How to: Environments, Approvals, and Checks Mapping on Azure DevOps

2 min readJul 7, 2021

This script and report extract all Environments and respective Approvals, and Checks to Multi-Stage Pipeline YAML on each Team Project within Azure DevOps

Press enter or click to view image in full size

An original script is available on my GitHub repository. See below this script:

Let’s go understand each command used.

  1. PowerShell script will receive the following parameters:
  • $PAT = Personal Access token to connect on Azure DevOps;
  • $Organization = Organization URL to list all Environments, Approvals, and Checks on Azure DevOps organization;
  • $Connstr = connection string to Azure SQL Database that stores the report information. To create this report, it’s necessary to create previously a Azure SQL Server and Database and run a script below:

2. Projects List = use this REST API to list all projects on the Azure DevOps organization.

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)")) }$UriOrganization = "https://dev.azure.com/$($Organization)/" $uriProject = $UriOrganization + "_apis/projects?`$top=500"$ProjectsResult = Invoke-RestMethod -Uri $uriProject -Method get -Headers $AzureDevOpsAuthenicationHeaderForeach ($project in $ProjectsResult.value)
{
Write-Host $project.name
}

3. Environments List = use this REST API to list all Environments on each Team Project

$uriEnvironments = $UriOrganization + "$($project.id)/_apis/distributedtask/environments?api-version=6.1-preview.1"    $EnvironmentsResult = Invoke-RestMethod -Uri $uriEnvironments -Method get -Headers $AzureDevOpsAuthenicationHeader    Foreach ($environment in $EnvironmentsResult.value)    
{
Write-Host $environment.name
}

4. Check Configurations Query = use this REST API to list all Approvers and Checks on each Environment

$body = @(
@{
type="queue"
id="1"
name="Default"
},
@{
type="environment"
id="$($environment.id)"
name="$($environment.name)"
}
) | ConvertTo-Json
$uriEnvironmentChecks = $UriOrganization + "$($project.id)/_apis/pipelines/checks/queryconfigurations?`$expand=settings&api-version=6.1-preview.1"$EnvironmentChecksResult = Invoke-RestMethod -Uri $uriEnvironmentChecks -Method Post -Body $body -Headers $AzureDevOpsAuthenicationHeader -ContentType application/json Foreach ($envcheck in $EnvironmentChecksResult.value)
{
Write-Host $envcheck.type.name
}

5. After extract all Environments, Approvals, and Checks, this information is stored in a table in Azure SQL.

6. After insert information into a table, I connected this database on Power BI:

Press enter or click to view image in full size
  • Team Project (1) = Filter report using Team Project field;
  • Environment (2) = Filter report using Environment field;
  • Approvals and Checks (3) = Filter report using Approvals and Checks types.
  • Report Information (4) = List all information about Environments, Approvals, and Checks. If the respective approval and check appear in this mapping, the same will be marked (green ticks on a grid).

One more time, I wanted to thank

and for their great help with PowerShell and for their great ideas with new reports.

--

--

Vinicius Moura
Vinicius Moura

Written by Vinicius Moura

Tech Solution Architect Manager na Accenture

Responses (3)