3

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?

2
  • How do you want to "integrate the bitbucket source control to VSTS"? Do you wanr the sync each changes from bitbucket repo to VSTS git repo after new changes are pushed to bitbucket repo (for any branches)? Commented Jun 18, 2018 at 7:46
  • Exactly, the same thing I want :) We are moving on VSTS. We already have our project on bitbucket and uses JIRA integration, and we don't want to break that integration. So, if any changes are done in VSTS for any repository, that should be reflected in Bitbucket, and vice versa. Commented Jun 18, 2018 at 10:33

2 Answers 2

11

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:[email protected]/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:[email protected]/username/repo.git $branch="$(Build.SourceBranch)".replace("refs/heads/","") git checkout $branch git push bitbucket $branch -f 
Sign up to request clarification or add additional context in comments.

20 Comments

Thanks Marina! one question here, how the build definition will be used by this powershell script? Can you please provide a bit information on what this script command does? Will it trigger all the builds I have in my VSTS account?
@DIGVJSS I added the annotation in the PowerShell script. And the build will be triggered only when new changes are pushed to bitbucket repo. The process as: new changes pushed to bitbucket repo -> build triggered -> new changes will also updated to VSTS git repo correspondlingly.
thanks, got it. So, the trigger is going to run the powershell script is it? Where can I add the powershell script?
@TomChantler yes I did manage to resolve the permissions issue, but only because my friend made me an admin on his repo. Sorry, I'm afraid I don't know what the specific permission needed is.
@oliver-clare thank you. I think your friend had to do that. "The administrators of a repository are the only users who can create a webhook on that repository." according to confluence.atlassian.com/bitbucket/…
|
0

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.

enter image description here

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.

enter image description here

3 Comments

Thanks for your answer brian. I am looking for something of automation. We are moving on VSTS. We already have our project running on Bitbucket and integrated with JIRA. If any change made on VSTS then that should be reflected on Bitbucket repo and vice versa.
You want to look into Git mirroring. (This is a Git thing, not a VSTS-specific thing.) Though I will say that there are a lot of wonky edge cases around consistency and it will complicate your team's workflow considerably. If you want to "manage" your source code through repo A and mirror it in repo B, I would recommend forbidding pushes to repo B so that it is a read-only view of repo A.
@BrianCristante—How is that done? Forbidding pushes to repo B, I mean. But doesn't git push --mirror <repo> also constitute a push, and would therefore be prohibited as well? More info at this Q&A.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.