How to get all repos in Azure DevOps

I have number of projects in Azure DevOps. I want to able to iterate through all Repos in Azure DevOps and get the name of the Repo, Creator of Repo and Last Updated/commit.

And get a notification when some one created new Repo?

2 Answers

We can list the repo info via REST API

List all repositories and get the name of the repo:

GET 

Get the Creator:

GET 

Note: we can get the branch creator via this API, I didn't find any APIs to get the repo creator.

Get latest commit:

GET 

Get a notification when some one created new Repo

We cannot create this notification, we can get a notification when someone updated the repo code. Please refer this link for more details: Supported event types  

Update1

//List project name $connectionToken="PAT" $base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)")) $ProjectUrl = "" $Repo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) $RepoName= $Repo.value.name Write-Host $RepoName //get latest commit info and branch creator $RepoID=$Repo.value.id Write-Host $RepoID ForEach ($Id in $RepoID) { //Get latest commit info $ProjectUrl = "" $CommitInfo = (Invoke-RestMethod -Uri $ProjectUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) $CommitID = $CommitInfo.value.commitId | Select-Object -first 1 Write-Host $CommitID $CommitUrl = "($CommitID)?api-version=6.0-preview.1" $LatestCommitInfo = (Invoke-RestMethod -Uri $CommitUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) Write-Host "LatestCommitInfo = $($LatestCommitInfo | ConvertTo-Json -Depth 100)" //Get branch name and creatot $BarchCreatorUrl = "" $CreateorInfo = (Invoke-RestMethod -Uri $BarchCreatorUrl -Method Get -UseDefaultCredential -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) Write-Host $CreateorInfo.value.name Write-Host $CreateorInfo.value.creator.displayName } 
7

Another option (easier with the Auth part) is to retrieve your Azure Repositories is through the AZ CLI using following commands:

  1. Log into Azure

    az login -t $tenant 
  2. First configure default values for organization and project, this will help you to not specify --project and --organization parameters in every az devops/repos command:

    az devops configure -d organization=$organizationUrl project=$project 
  3. List repositories of your subscription and default project and organization

    az repos list --subscription $subscription 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like