How to sync repo in bitbucket to Visual studio team service?

萝らか妹 提交于 2019-11-28 09:33:55

To sync changes from bitbucket repo to VSTS git repo automatically, you can achieve it by using a VSTS build definition. Detail steps as below:

1. Create a build definition with Bitbucket repo

When creating a VSTS build definition -> Select the Bitbucket repo you want to sync -> create.

2. Enable continuous integration

In the build definition -> Triggers Tab -> Enable continuous integration -> Include all branches with *.

3. Add PowerShell task with the script to sync bitbucket repo with VSTS git repo

Add a PowerShell task with below script:

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

For the detail steps to add and config the PowerShell task as below:

Edit your build definition -> Click + to add a task for your agent phase -> Search powershell task -> click Add -> click the PowerShell task you added -> select Inline type -> then add your powershell script in the Script option -> Save build definition.

Now no matter which branch is updated in your bitbucket repo, VSTS git repo will be synced automatically.


Yo sync changes from VSTS git repo to bitbucket repo, you can create another CI build to achieve it. Detail steps as below:

1. Create a CI build with VSTS git repo

2. Enable continuous integration

3. Add a PowerShell task with below aspects

if ( $(git remote) -contains 'bitbucket' )
{git remote rm bitbucket
echo 'remove remote bitbucket'
}

git remote add bitbucket https://username:password@bitbucket.org/username/repo.git 
$branch="$(Build.SourceBranch)".replace("refs/heads/","")
git checkout $branch
git push bitbucket $branch -f

When you connect your Bitbucket account to VSTS, you are setting up build triggers to run automated builds on pull requests or merges. This is what is called "continuous integration" in the DevOps world.

Consider reading the documentation for more information on this topic.

You will continue to "manage" your Bitbucket repos on Bitbucket. It's totally separate. If you want to manage everything through VSTS, you should import your Bitbucket repo to your VSTS account.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!