peyman gilmour
peyman gilmour

Reputation: 1218

Migration from internal network TFS to VSTS

We have an internal server in a company for TFS which is contained in more than 100 projects. We are walking on the edge! Therefore the company made a decision to move all the projects to Visual studio team services (VSTS). Unfortunately, It cost so much time if we are gonna move the projects one by one.

I also tried Git-TF or Git-TFS but it was not successful and so frustrating. I got some errors every time and then I gave up.

Is there any way to move all the projects to VSTS at once or at least import them by VSTS? (For example, i import the Github projects directly from VSTS. But now instead of Github we have a computer as a server inside the company)

I appreciate that any suggestion or help.

Upvotes: 0

Views: 521

Answers (3)

Layne Carder
Layne Carder

Reputation: 11

This is a comprehensive script for automating the clone of all your git repos to your Azure DevOps project using powershell, and the TFS api. I'm going from TFS 2018:

# get all repositories
$TfsUrl = "http://tfs-server:8080/tfs/DefaultCollection/myProject/_apis/git/repositories?api-version=4.1"
$repos = Invoke-RestMethod -Uri $TfsUrl -Method Get -ContentType "application/json" -UseDefaultCredentials

# set the auth header from a PAT
$myPAT = "aaaaaabbbbbbbbbbbbcccccccccccdddddddd111111123"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("[email protected]:$myPAT")))
$headers = @{Authorization=("Basic $base64AuthInfo")}

# get Azure DevOps project id
$adoPURL = "https://dev.azure.com/myOrganization/_apis/projects?api-version=4.1"
$adoProjectId = ((Invoke-RestMethod -Uri $adoPURL -Method Get -ContentType "application/json" -Headers $headers).value | where {$_.name -eq "myADOProject"}).id

# loop through each TFS repository, clone it, and push it to your Azure DevOps project
foreach ($repo in $repos.value) {
    Write-Host "cloning $($repo.name)"

    # set to the root folder, and mirror clone the repo
    Set-Location C:\clone_repo
    git clone --mirror http://tfs-server:8080/tfs/DefaultCollection/myProject/_git/$($repo.name)

    # create the new remote git repo in your Azure DevOps project
    $json = '{"name":"' + $($repo.name) + '","project":{"id":"' + $adoProjectId + '"}}'
    $vUrl = "https://dev.azure.com/myOrganization/_apis/git/repositories?api-version=4.1"
    Invoke-RestMethod -Uri "$vUrl" -Body $json -ContentType "application/json" -Method POST -Headers $headers

    # push the morrored repo to the remote
    Set-Location "$($repo.name).git"
    git remote set-url --push origin https://dev.azure.com/myOrganization/myADOProject/_git/$($repo.name)
    git push --mirror
}

Upvotes: 1

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31003

If you want to have a high fidelity database migration, you should check @DenverDev's reply, he has provided correct links there.

If you only want to migrate a complete Git Repository from TFS to VSTS, you could try the steps in this blog:

  1. Clone the Git repo with everything in it: git clone [tfs git url] --mirror

  2. Add the new remote: git remote add vsts [vsts git url]

  3. Push all the changes: git push vsts --mirror

Upvotes: 2

DenverDev
DenverDev

Reputation: 497

Microsoft provides a fairly comprehensive guide for migrating from TFS to VSTS.

Migration Options

Migrate to Visual Studio Team Services

If you have already tried this and are having specific errors, please post additional information.

Upvotes: 0

Related Questions