【问题标题】:Sync Github to Azure Devops Repo将 Github 同步到 Azure Devops 存储库
【发布时间】:2021-12-14 14:36:36
【问题描述】:

我在 Github 有一个 git repo,像往常一样有几个分支和master

我想每隔 X 间隔运行一个管道,基本上将所有内容从 Github 存储库镜像到 Azure 存储库,丢弃在 Azure 端所做的任何不同。所以基本上是一面镜子。

到目前为止我做了什么:

  • 创建了一个新项目
  • 使用 import 选项从 Github 导入 repo
  • 创建了一个azure.yaml,内容如下:
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
  • 创建了一个管道并使用上述内容运行

管道运行正常,没有出现故障。 bash的内容如下:

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

无论我做什么,我都无法覆盖更改并将 Azure 存储库与 Github 的精确副本同步。我知道修剪和创建镜像,但是我当然对上述方法不起作用的原因感兴趣。

我错过了什么?

【问题讨论】:

  • 您的脚本甚至没有尝试推送 - 您尝试过什么,它是如何失败的?
  • 是的!我忘了在最后添加git push --force origin,因为我不明白 azure 是如何工作的(管道机器!== 保存 repo 的机器)。我必须打开管道的权限才能强制推送,它起作用了。如果您将其写在答案中,我会接受。

标签: git github azure-devops azure-pipelines azure-repos


【解决方案1】:

您的管道需要将更新后的存储库推送到 Azure DevOps git 存储库。

git push -f origin

【讨论】:

    猜你喜欢
    • 2021-03-05
    • 2020-01-13
    • 2021-04-30
    • 2021-09-29
    • 2022-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-07
    相关资源
    最近更新 更多