Keeping Azure DevOps repo in sync with bitbucket after a pull request

celsocoutinho March 17, 2020

Hi guys!

After a pull request on Azure DevOps, from a feature branch to master, my repository on Azure DevOps is now ahead of the bitbucket repository, and I need to sync them.

Problem is, I can't. I tried running the powershell script below on an Azure Pipeline, as per the link.

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 

But this is failing with the following error:

fatal: unable to access '<a href="https://bitbucket.org/***/repo.git/':">https://bitbucket.org/***/repo.git/':</a>; URL using bad/illegal format or missing URL 

Any idea what I might be doing wrong? I copy pasted the script from the link, changing the username and password by the credentials I use to connect to my bitbucket account, and repo with the repository name.

 

EDIT

I was not encoding neither the username nor the password, and by changing that the pipeline is now executed until the end. However, as weird as it is, no change is being persisted on bitbucket. The powershell output is as follows:

Switched to a new branch 'master'

Branch 'master' set up to track remote branch 'master' from 'origin'. 

Everything up-to-date 

 

EDIT 2

Ok, I dug up the problem. Some data actually passed from Azure DevOps to bitbucket already: the first commit within the pull request. All other commits didn't go through.

2 answers

1 accepted

0 votes
Answer accepted
celsocoutinho March 19, 2020

Okay, I finally managed to get this working by forcing a push in master (I can't find the exact command I used, if someone can remind me, I will update this answer).

The repository history was a little bit messed up though (explained below), but at least it is working and even though the history is not exactly in sync, the files are.


------------------------------
Azure DevOps repo history

Commit XXX

Commit AAA

Bitbucket repo history

Commit XXX

Commit YYY

Commit AAA

------------------------------


For someone using a similar configuration, I recommend making sure the pull requests are done on bitbucket, and not on Azure DevOps. This way the pipeline will always trigger after changes on the main repo, on bitbucket, and never the other way around.

I was also having a problem related with permissions, namely:

Pushes to this branch are not permitted; you must use a pull request to update this branch.

I managed to fix it by following these guidelines

0 votes
celsocoutinho March 18, 2020

I fixed this by encoding the password, following the table below: 

 

Screenshot_12.png

celsocoutinho March 18, 2020

In fact, the pipeline runs until the end, but no change persists on bitbucket! Any idea on what might be happening? 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events