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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.