Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Update Azure Repository with Bitbucket Repository.

Osama Abdul Ghafoor May 8, 2023

Hi Everyone,

I have imported my Bitbucket Repository to Azure. Now, Is there a way to keep my Azure Repository updated with Bitbucket Repository?

Thanks

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 10, 2023

Hi @Osama Abdul Ghafoor,

If you make a clone of the Bitbucket Cloud repo on your machine with the --mirror option, you have a copy of the repo with all branches:

git clone --mirror <bitbucket_repo_url>

You can then navigate to the directory of the mirror clone and push to an empty Azure repo:

git push --mirror <azure_repo_url>

In order to update the mirrored repository in Azure, you can run the following commands in the directory of the mirror clone

git fetch -p origin
git push --mirror <azure_repo_url>

You could write a script that performs these operations (fetch and push) and schedule it to run periodically.


Another option is to use Bitbucket Pipelines to automate this process and run a pipelines build every time there is a push to the Bitbucket Cloud repo. You could use a bitbucket-pipelines.yml file similar to that one:

image: atlassian/default-image:4

pipelines:
default:
- step:
clone:
enabled: false
name: 'Mirror repository'
script:
- git clone --mirror ${BITBUCKET_GIT_SSH_ORIGIN}
- cd ${BITBUCKET_REPO_SLUG}.git
- git push --mirror <azure_repo_url>

Such a pipeline will run on every push to the repo, but you can also use a custom pipeline and schedule it to run at certain times/days.

You will need to set up authentication details to push to the Azure repo. You could use user-defined repository variables for any credentials if you want to use HTTPS. If you want to use SSH instead, you can set up SSH keys in Pipelines, and upload the public key to an Azure account that has write access to that Azure repo:

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events