Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kunduso/MigrateToAzureRepos
a powershell script to bulk migrate repositories from bitbucket to Azure Repos
https://github.com/kunduso/MigrateToAzureRepos
azure-devops bitbucket git powershell
Last synced: 3 months ago
JSON representation
a powershell script to bulk migrate repositories from bitbucket to Azure Repos
- Host: GitHub
- URL: https://github.com/kunduso/MigrateToAzureRepos
- Owner: kunduso
- Created: 2020-07-10T10:20:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-01T03:32:31.000Z (about 2 years ago)
- Last Synced: 2024-05-18T06:33:58.552Z (6 months ago)
- Topics: azure-devops, bitbucket, git, powershell
- Language: PowerShell
- Homepage:
- Size: 19.5 KB
- Stars: 3
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - kunduso/MigrateToAzureRepos - a powershell script to bulk migrate repositories from bitbucket to Azure Repos (PowerShell)
README
[Open in Visual Studio Code](https://open.vscode.dev/kunduso/MigrateToAzureRepos)
![Image](https://skdevops.files.wordpress.com/2020/07/21.-migratingfrombbtoar-image0-1.png)
## MotivationI had a task at hand to migrate all repositories from a particular team in bitbucket to Azure Repos. I knew about the UI based tool that is available to import repositories from AzureDevops but there is a limitation there. Only one repository could be moved at a time. And each time (manually) information has to be provided. If you are interested in knowing more about it please visit my article on that [here](http://skundunotes.com/2020/07/10/migrating-a-repository-from-bitbucket-to-azure-repos-ui-based/).
I had to move more than three dozen bitbuket repositories and that approach did not sound exciting and hence I automated the task. Here is a link to my [note](http://skundunotes.com/2020/07/10/migrating-a-repository-from-bitbucket-to-azure-repos-using-powershell/)
## Prerequisites
### **Installations**
Install Azure CLI from [here](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)
Install [Atlassian.Bitbucket Powershell module](https://www.powershellgallery.com/packages/Atlassian.Bitbucket/0.14.0) from Powershell Administrator console.
### **Input Parameters**
BitBucketUserName : your bitbucket user name
BitBucketEmailAlias : email id associated with bitbucket
BitBucketPassword : bitbucket password
RootFolderForProjects : local folder path for migration work. Folder does not need to exist. Folder will be deleted after the script runs successfully.
AzureDevopsPAT : AzureDevops team project PAT
$AzureDevopsOrgURL : similar to https://dev.azure.com/MyOrganizationName/
AzureDevopsTeamName : project team name in AzureDevops## Usage
-Open windows powershell as admin before you run the script
-Copy/download powershell file and execute below command.\MigrateToAzureRepos.ps1 -BitBucketUserName "$(YourBitBucketUserName)" -BitBucketEmailAlias "$(YourBitBucketEmailID)" -BitBucketPassword "$(YourBitBucketPassword)" -RootFolderForProjects "$(LocalMachineFolderPath)" -AzureDevopsPAT "$(AzureDevopsPAT)" -AzureDevopsOrgURL "$(AzureDevopsOrgURL)" -AzureDevopsTeamName "$(YourAzureDevopsTeamName)"
## Algorithm
Create local folder for clone work
Login to Bitbucket
Get a list of bitbucket teams
For each bitbucket team, get a list of projects associated with that team
-For each projects, get a list of repositories associated with that project
-For each repository,
-clone the repo to local
-check if a repository exists in Azure Repos, if not create one
-push code from local to repo in Azure Repos
continue until all repositories in particular project are migrated
continue until all projects in particular bitbucket team are migrated
continue until all teams in particular bitbucket login are migrated
Logout of bitbucket
Delete local folder
Delete AzureDevps PAT from environment
## Error
If you get an error like the one below, most probably the powershell module `Atlassian.Bitbucket` was not installed. Install that following the steps mentioned above.
```diff
-import-module : The specified module 'Atlassian.Bitbucket' was not loaded because no valid module file was found in any module directory.
-At C:\ed\MigrateToAzureRepos\MigrateToAzureRepos.ps1:14 char:1
-+ import-module Atlassian.Bitbucket
-+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- + CategoryInfo : ResourceUnavailable: (Atlassian.Bitbucket:String) [Import-Module], FileNotFoundException
- + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
```
If you get this error even after installing the module, open a new Administrator Powershell and execute the powershell file `MigrateToAzureRepos.ps1` with appropriate parameters.
Apart from that if there are any issues with executing the powershell file, please let me know.## Contribution/Feedback
Please submit a pull request with as much details as possible