Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

azure devops - How to sync repo in bitbucket to Visual studio team service?

I am very new to VSTS platform. In one of my project, I am trying to integrate the bitbucket source control to VSTS. By this way I should be able to see the updates made on bitbucket onto the VSTS account.

I have tried creating build on VSTS, but that only shows the commits history of the selected repository of bitbucket.

Is there a way to manage all the bitbucket changes on VSTS as source control?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

enter image description here

2. Enable continuous integration

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

enter image description here

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.

enter image description here

enter image description here

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

enter image description here 2. Enable continuous integration enter image description here 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...