Edit on GitHub
Report issue
Page history

Mirroring an Azure DevOps repository to Cloud Source Repositories

Author(s): @manokhina ,   Published: 2021-03-05

Anastasiia Manokhina | Strategic Cloud Engineer | Google

Contributed by Google employees.

This tutorial shows how to set up mirroring from an Azure DevOps repository to Cloud Source Repositories.


This tutorial uses billable components of Google Cloud, including Cloud Source Repositories. (Check the free usage limits.)

Use the pricing calculator to generate a cost estimate based on your projected usage.

Before you begin

For this tutorial, you need a Google Cloud project. You can create a new one, or select a project that you have already created.

  1. Create a Google Cloud project.
  2. Enable billing for the project.
  3. Enable the Cloud Source Repositories API.

On the Azure side, you need to have an Azure DevOps account and an Azure DevOps project.

Initial setup

  1. Install the Mirror Git Repository extension for your Azure organization.
  2. In the Google Cloud Console, open Cloud Shell.
  3. In Cloud Shell, create the Git repository in Cloud Source Repositories that will be the mirror of the Azure repository:

    gcloud source repos create azure-csr-mirror

Generating static credentials

In order for Azure Repos to push to your Git repository to Cloud Source Repositories, you must complete an OAuth 2.0 authorization flow to generate static credentials for Cloud Source Repositories.

Important: The generated credentials are tied to the Google Account used to create them. Mirroring stops working if the Google Account is closed or loses access rights to the Git repository in Cloud Source Repositories.

  1. In Cloud Source Repositories, go to the All Repositories page.
  2. Click the name of your repository.
  3. On the Add code to your repository page, under Select your preferred authentication method, select Manually generated credentials, and then click Generate and store your Git credentials.


    The Cloud Source Repositories site (https://source.developers.google.com), which identifies itself as Google Cloud Development, requests the credentials on your behalf.

  4. Choose your Google Account in the Sign in with Google dialog:


    The following dialog appears, requesting permission to view and manage your data.


  5. If you agree to the request for access, click Allow.

  6. On the Configure Git page, note the git-[USERNAME] and the highlighted text area. This will be the token used in the next steps.


Creating an Azure pipeline

  1. In the project containing the repository, select Pipelines.

  2. Select Create pipeline.

  3. Select Use the classic editor to create a pipeline without YAML.

  4. Select Azure Repos Git as a source for code. Click Continue.

  5. At the top of the page, select Empty job as a template.

  6. Rename the pipeline to Clone to Cloud Source Repo.

  7. Click + Next to Agent job 1 to add the task. Find the Mirror Git Repository task and add it to the pipeline.

  8. Click the task in the left pane. Change its display name if needed.

  9. In the Source Git Repository field, paste the link to your Azure repository: https://dev.azure.com/[YOUR_ORGANIZATION]/[PROJECT_NAME]/_git/[PROJECT_NAME]

  10. A personal access token (PAT) is used as an alternative password to authenticate into Azure DevOps. In the Source Repository - Personal Access Token field, paste the token created using the procedure in the Use personal access tokens article.

  11. In the Destination Git Repository field, paste the URL of your repository in Cloud Source Repositories: https://source.developers.google.com/p/[PROJECT_ID]/r/[REPOSITORY_NAME]

  12. Get the username and the token generated in the Configure Git section in Cloud Source Repositories and insert it to the Destination personal access token field as follows:


    In the token, replace the slash signs with its encoded variant, %2F. So if your username is user and your token starts with 1//..., the token to be inserted is the following: git-user:1%2F%2F...

  13. Click Save & Queue.

  14. Optionally, add a comment.

  15. Click Save & Run.

  16. You are redirected to the pipeline page, where you can see your job running in the Jobs tab. When it finishes running, you will see the status Success near the job name.

  17. In Cloud Source Repositories, go to the All repositories page.

  18. Click the name of your repository, which in this example is azure-csr-mirror.

  19. Click to the main branch. The files and commit history from the original repository should appear.

    Note: If you want to do this regularly, note that service account keys expire after 30 days. Ensure that there is an established process of maintaining and regular rotation of keys.

Cleaning up

Deleting the project

The easiest way to eliminate billing and avoid incurring charges to your Google Cloud account for the resources used in this tutorial is to delete the project that you created for the tutorial:

  1. In the Cloud Console, go to the Manage resources page.
  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

Revoking the credentials

If you want to revoke the generated credentials, go to the Apps with access to your account page under your Google Account, select Google Cloud Development, and click Remove access.

What's next

Submit a tutorial

Share step-by-step guides

Submit a tutorial

Request a tutorial

Ask for community help

Submit a request

View tutorials

Search Google Cloud tutorials

View tutorials

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.