Count of Deployments by Environment and filterable by date in Azure DevOps

Izzy 0 Reputation points
2024-10-06T19:53:57.0166667+00:00

How can I get a a count of Deployments by Environment and filterable by date in Azure DevOps? Are there any widgets in Azure DevOps that can get me a count of all deployments made to a specific environment and filter by month?

Community Center Not monitored
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Marcin Policht 49,640 Reputation points MVP Volunteer Moderator
    2024-10-06T20:03:57.9866667+00:00

    I'm not aware of any widgets, but workarounds include PowerShell and Power BI

    Install-Module -Name AzureDevOps
    
    # Define variables
    $organization = "your-organization-name"
    $project = "your-project-name"
    $envName = "your-environment-name"  # Filter by environment
    $startDate = "2024-09-06T00:00:00Z"  # Filter by start date (ISO 8601 format)
    $endDate = "2024-10-06T23:59:59Z"    # Filter by end date
    $pat = "your-personal-access-token"
    # Encode PAT for authorization
    $headers = @{
        Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
    }
    # Build API URL for deployments
    $url = "https://dev.azure.com/$organization/$project/_apis/release/deployments?api-version=6.0&minStartedTime=$startDate&maxStartedTime=$endDate"
    # Make API call
    $response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
    # Filter by environment and count deployments
    $deploymentCount = ($response.value | Where-Object { $_.releaseEnvironment.name -eq $envName }).Count
    # Output the result
    Write-Output "Deployment count for environment '$envName' between $startDate and $endDate: $deploymentCount"
    
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


  2. AmaranS 7,270 Reputation points Microsoft External Staff
    2024-10-07T03:47:21.6533333+00:00

    Hi Izzy,

    Thank you for reaching out to us on the Microsoft Q&A forum.

    This topic is currently not supported in the Q&A forums.

    I recommend initiating a new discussion through the Developer Community

    Moderators are readily available there to assist you and provide guidance.

    Please don't forget to Accept answer and close this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.