Created
August 4, 2022 12:10
-
-
Save kiwimato/1a47d25226268dd5f580cbd45cb6f741 to your computer and use it in GitHub Desktop.
This script will help with updating multiple Azure DevOps repositories at once, useful when there are too many repos to point and click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script will help with updating multiple Azure DevOps repositories at once, useful when there are too many repos to point and click | |
# For example on line 23, the command updates all repos that match PATTERN to only allow squash merge types. | |
$org="organization" | |
$project="Project" | |
$PAT="XXPATXX" | |
# First login: | |
az devops configure --defaults organization=https://dev.azure.com/$org project=$project | |
# Get a PAT and replace PAT here: | |
Write-Output $PAT | az devops login --organization "https://dev.azure.com/$org" | |
# Get all repos | |
$listOfRepos = az repos list | ConvertFrom-Json | |
# Replace "PATTERN" with your repo pattern, for example: wealth | |
$reposIds = $listOfRepos | Where-Object{$_.name -like "PATTERN*"} | %{$_.id} | |
# Update policy | |
foreach $(repoId from $reposIds){ | |
az repos policy merge-strategy create --repository-id $repoId --blocking true --branch master --enabled --allow-no-fast-forward false --allow-rebase false --allow-rebase-merge false --allow-squash true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment