Home > Back-end >  Sync Github to Azure Devops Repo
Sync Github to Azure Devops Repo

Time:10-30

I have a git repo in Github, with couple of branches and master as usual.

I want to run a pipeline every X interval to basically mirror everything from Github repo into Azure Repo, discarding whatever different has been done on Azure side. So basically a mirror.

What I have done so far:

  • created a new Project
  • imported the repo from Github using import option
  • created a azure.yaml with the following contents:
name: Keep clone up to date
variables:
  REMOTE_ADDR: 'https://github.com/some-user/some-repo.git'
stages:
  - stage: running_git_commands
    displayName: running_git_commands
    jobs:
      - job: initiate
        displayName: initiate
        continueOnError: false
        steps:
        - checkout: self
          clean: true
          persistCredentials: true
          displayName: run_commands
        - bash: | 
            git checkout master
            git remote add repoGithub $(REMOTE_ADDR)
            git fetch repoGithub master
            git reset --hard repoGithub/master
            git pull --rebase repoGithub master
  • created a pipeline and ran with the above contents

The pipeline runs OK without failures. The contents of the bash are as follows:

Starting: Bash
==============================================================================
Task         : Bash
Description  : Run a Bash script on macOS, Linux, or Windows
Version      : 3.189.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /some/vsts/path/to.sh
Switched to a new branch 'master'
Branch 'master' set up to track remote branch 'master' from 'origin'.
From https://github.com/some-user/some-repo
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> repoGithub/master
HEAD is now at someCommitHex someSemverString
From https://github.com/some-user/some-repo
 * branch            master     -> FETCH_HEAD
Already up to date.
Finishing: Bash

no matter what I do, I cannot get to overwrite changes and sync the Azure repo with an exact copy of Github one. I am aware of pruning and creating a mirror, however I am certainly interested in why the above approach does not work.

What am I missing?

CodePudding user response:

Your pipeline needs to push the updated repository to the Azure DevOps git repository.

git push -f origin
  • Related