Bulk pushing to Azure DevOps

We recently needed to push multiple git respositories from one Azure DevOps instance to another. Unfortunately DevOps doesn't provide a native way of doing this so scripting required.

This presumes you've already pulled all the repositories to your local machine. See Cloning all repositories from Azure DevOps using Azure CLI - Simon Wahlin for a script to do this.


$Organization = "https://dev.azure.com/org"
# Make sure we are signed in to Azure
$AccountInfo = az account show 2>&1
try {
$AccountInfo = $AccountInfo | ConvertFrom-Json -ErrorAction Stop
}
catch {
az login --allow-no-subscriptions
}
# Make sure we have Azure DevOps extension installed
$DevOpsExtension = az extension list --query '[?name == ''azure-devops''].name' -o tsv
if ($null -eq $DevOpsExtension) {
$null = az extension add --name 'azure-devops'
}
# Destination project in DevOps
$Project = "destination project"
# Location of repositories
$source = "C:\sourcepath"
Get-ChildItem -path $source -Directory | ForEach-Object {
# Create a repository with the same name as the folder
az repos create --name $_.Name --project $Project --org "https://dev.azure.com/org"
# Move to current folder
set-location $_.FullName
# Change the remote origin
git remote set-url origin "https://org@dev.azure.com/org/project/_git/$($_.Name)"
# Push the repo
git push -u origin --all
}
view raw DevOpsUpload hosted with ❤ by GitHub

Comments

Popular posts from this blog

DFS "Waiting for Initial Replication"

Avoid Microsoft Intune if you use G-Suite and Android

Setting Wallpaper for a Remote Desktop Session