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.
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
$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 | |
} | |
Comments
Post a Comment