How to: Create Dashboard to visualize Environments and Deployments on Azure DevOps

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

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 Environments and Deployments on each project;
  • $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.

$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

$EnvironmentsResult = Invoke-RestMethod -Uri $uriEnvironments -Method get -Headers $AzureDevOpsAuthenicationHeader    Foreach ($environment in $EnvironmentsResult.value)    
{
Write-Host $environment.name
}

4. Environmentdeployment Records List = use this REST API to list all Deployments on each Environment

$EnvironmentDeploymentResult = Invoke-RestMethod -Uri $uriEnvironmentDeployment -Method get -Headers $AzureDevOpsAuthenicationHeader        Foreach ($envdeploy in $EnvironmentDeploymentResult.value)        
{
Write-Host $envdeploy.stageName
}

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

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

  • Project Name (1) = Filter report using Team Project Name parameter;
  • Environment Name (2) = Filter report using Environment Name parameter;
  • Pipeline Definition Name (3) = Filter report using Pipeline Definition Name parameter;
  • Stage Name (4) = Filter report using Stage Name parameter;
  • Job Name (5) = Filter report using Job Name parameter;
  • Result (6) = Filter report using Result (failed, succeeded) parameter;
  • Environments and Deployments information (7) = list all information about Environments and Deployments (Project Name, Environment Name, Pipeline Definition, Stage Nam,e Job Name, Result, Queue Time, Start Time and, Finish Time).

DevOps Consultant at N3