set default reviewers for pull requests globally

Copper Contributor

Is there a way that I can set 3 reviewers for all protected branches (we have 5) globally without having to go into all of our 40+ repositories and doing it for 4 branches each?    I tried to do this with manage repositories and then all repositories but the reviewers I added dont show in the individual repos when I drill down.  I need this so my merge automation works and approvers are already set as reviewers.

Capture.JPG

1 Reply

$mergeReposFile = Join-Path $PWD.Path ".\mergeReposInfo.json"
$mergeRepos = Get-Content -Raw -Path $mergeReposFile | ConvertFrom-Json
$DevOpsOrganization = "https://dev.azure.com/company"
$DevOpsProject = "Company"
$Reviewers = "email address removed for privacy reasons"

foreach ($repoitem in $mergeRepos.repositories) {


$repositoryName = $repoitem.name
Write-Output "Repository: $repositoryName "
$repositoryID= $repoitem.id


$AppliedPolicy = az repos policy required-reviewer create `
--blocking $false `
--branch $repoitem.mastername `
--enabled $true `
--message "Automatically added as reviewer for by policy for $($Repository.name) repo." `
--repository-id "$($repositoryID)" `
--branch-match-type "exact" `
--org $DevOpsOrganization `
--project $DevOpsProject `
--required-reviewer-ids $($Reviewers -join ";") | ConvertFrom-Json

}