gitbuildazure-devopsazure-pipelinesvnext

vNext Build pipeline to sync remote git into local repository


We got code stored and worked on inside BitBucket. I am trying to sync that code over to a git repository inside VSTS Online by using a build pipeline. However, i can't figure out what build steps to use in order to pull the files from the BitBucket git and push them into the VSTS git.

My idea was something like this:

enter image description here

The "Get sources" fetches the files from the remote BitBucket repository and then the Command Line Script is meant to save them to the local VSTS git by first switching to the master branch and then pull from the remote git. I am however unsure what commands and/or job modules to use for this task.

The picture is from inside the local VSTS git repo under the Build and release tab.


Solution

  • To sync changes from Bitbucket repo to VSTS git repo, you can add a PowerShell task to achieve it.

    The PowerShell script as below:

    if ( $(git remote) -contains 'vsts' )
    {git remote rm vsts
    echo 'remove remote vsts'
    }
    
    $branch="$(Build.SourceBranch)".replace("refs/heads/","")
    git remote add vsts https://Personal%20Access%20Token:PAT@account.visualstudio.com/project/_git/repo
    git checkout $branch
    git push vsts $branch -f
    

    And for similar situations, you can also refer the post How to sync repo in bitbucket to Visual studio team service.