0

I am managing an Azure DevOps organization which is having 300+ projects. I want to know how many releases are happing every month across the projects.

I saw we have REST API to get release from one specific project. https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=6.0

But this will require me to extract all project name using other REST API and pass in the above manually.

Is there any API which can give me release from all projects from a DevOps organization?

If there is any single API which will provide me this details is fine.

If not, any PowerShell, CLI script which will loop through each project, pass to above API and extract a report for me to get all projects releases will be fine.

Any other mechanism suggestion like pipeline etc. will also be appreciated.

Thanks Den

Den Wahlin
  • 55
  • 5

1 Answers1

0

As far as I know, there is no single API can directly list all releases from a DevOps Organization.

You can use the Rest API(Projects - List) to loop through all the projects, and then get the releases(Releases - List) in the project respectively.

Here is PowerShell example:

$token = "PAT"

$url="https://dev.azure.com/OrganizationName/_apis/projects?api-version=6.0"

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



$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json

Foreach($projectName in $response.value.name)
{
  echo $projectname
  $url1=”https://vsrm.dev.azure.com/OrganizationName/$($projectname)/_apis/release/releases?api-version=6.0“
 
  $response = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json

  echo $response | ConvertTo-Json -Depth 99 |  Out-File "yourPath\file.json" -Append


}
Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • Hi Kevin Lu-MSFT ,Thanks for that but it is giving me unauthorized error. Invoke-RestMethod : The remote server returned an error: (401) Unauthorized . PAT is correct. $response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json Invoke-RestMethod: Response status code does not indicate success: 401 (Unauthorized). – Den Wahlin Sep 23 '21 at 07:27
  • Are you using the PAT in the script? https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page You can try to give the full access for the PAT and test it. – Kevin Lu-MSFT Sep 23 '21 at 07:28
  • I gave full access to my PAT.. here is the error $response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json Invoke-RestMethod: Response status code does not indicate success: 401 (Unauthorized). – Den Wahlin Sep 23 '21 at 07:30
  • Could you please update your question and share your PowerShell sample? Then I can help you check this issue. Note: you need to remove the PAT and Orgname info. – Kevin Lu-MSFT Sep 23 '21 at 07:33
  • On the other hand, you can use this token to run the two APIs separately (Not use PowerShell)to check whether you have sufficient permissions – Kevin Lu-MSFT Sep 23 '21 at 07:45
  • Hi Kevin Lu-MSFT, Thanks, There was some syntax error and now it is able to write output in line using echo as you mentioned, appreciate that. Actually I am running through Azure DevOps pipeline using PowerShell task and checking if there is anyway to export inline output to file? – Den Wahlin Sep 23 '21 at 08:24
  • You can try to use the following script: `echo $response | ConvertTo-Json -Depth 99 | Out-File "yourpath\file.json" -Append` to output the response to a json file. If you need to get this file, you can publish the file as Pipeline artifacts. – Kevin Lu-MSFT Sep 23 '21 at 08:41
  • Hi, First API is giving just 50 record in the beginning. I tried to add top variable with more number but its not working. am i giving top parameter incorrectly? $url="https://dev.azure.com/uniperteamservices/_apis/projects?api-version=6.0&$top=5000" if i am directly hitting from browser i can see more record but in powershell script its not working – Den Wahlin Sep 23 '21 at 11:21
  • Hi Kevin Lu-MSFT, The first API is giving just 100 record, when i am adding more parameter, it is not showing output. Am I am doing something wrong ? This works if I am directly hitting url in browser https://dev.azure.com/uniperteamservices/_apis/projects?api-version=6.0&$top=500 – Den Wahlin Sep 27 '21 at 11:01