本文介绍了Git:定期将一个回购复制到公司外部无法访问的另一个回购中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在我们公司的一个项目上工作;该项目以 Azure DevOps (带有git的在线"版本)进行管理.
我们在 Azure DevOps 中将公司C1称为项目P1.

只要您具有正确的凭据,就可以从任何地方访问该公司的DevOps.

项目P1打算交付给另一家公司;我们称之为C2.

C2还有一个 Azure DevOps 公司网站,其中包含一些存储库.

C2希望每天根据其自己的Azure管道(命名约定,代码覆盖范围等)验证开发.

最简单的方法是将P1从C1镜像到C2,然后仅在C2/P1中工作.问题在于,禁止在公司域之外访问C2,并且大多数开发人员都不在C2建筑物中进行开发.

我们有以下想法:

  • 每天,在C2楼中的开发人员计算机上,对C1/P1进行拉取;
  • 此后,从本地向C2/P1进行推送.

遗憾的是,这种方法仅在没有合并限制,开发者计算机始终处于运行状态等情况下才有效.

是否存在某种git方法可以每天将C1/P1完全复制到C2/P1?

谢谢.

解决方案

您可以创建另一个管道来运行git命令来克隆C1/P1并推送到C2/P1.请检查以下详细步骤:

1,在C1/P1中创建一个新管道,以将C2/P1与C1/P1同步(在经典UI管道中).在管道编辑页面上,单击获取源文件检查 不同步源文件,以跳过按代理作业克隆C1/P1的操作.

2,添加一个powershell任务以在以下脚本中运行.下面的脚本将克隆C1/P1,然后将远程URL更改为C2/P1,然后将代码推送到C2/P1.您将需要使用PAT进行选育.检查

2,在出现的提示窗口中,输入C1/P1和PAT对应的C1/P1的天蓝色资源.

3,然后点击触发器标签以启用持续集成.然后,当对C1/P1进行任何更改时,将触发C2/P1的管道.

还可以从C2/P1的项目设置页面添加服务连接.在此处查看了解详情

希望上面有帮助!

we are working on a project in our company; the project is managed in Azure DevOps (the "online" version, with git).
Let's call the project P1, in Azure DevOps for company C1.

This company DevOps can be accessed from anywhere, provided you have the correct credentials.

The project P1 is meant to be delivered to another company; let's call it C2.

C2 also have an Azure DevOps company website, containing some repos.

C2 wants to validate the development each day against its own Azure pipeline (naming convention, code coverage, etc.).

The easiest thing to do would be to mirror P1 from C1 to C2 and then work only in C2/P1. The problem is that access to C2 is forbidden outside of the company domain, and that most of the developer don't develop in C2 building.

We had the following idea:

  • each day, on a developer computer who is in C2 building, a pull is performed on C1/P1;
  • just after that, a push is performed from local to C2/P1.

Sadly, this approach only works if there are no merge conflit, if the developer computer is always up and running, etc.

Is there some kind of git approach that will allow C1/P1 to be completely copied each day to C2/P1?

Thanks.

解决方案

You can create another pipeline to run git commands to clone the C1/P1 and push to C2/P1. Please check below detailed steps:

1, create a new pipeline in C1/P1 to sync C2/P1 with C1/P1.(In classic UI Pipeline). On the pipeline edit page, Click Get source and Check Don't sync sources to skip cloning C1/P1 by agent job.

2, Add a powershell task to run below scripts. Below script will clone C1/P1 and then change the remote url to C2/P1, then push the code to C2/P1. You will need to use PAT to anthenticate. Check here to generate PAT with Code read and write scope

- powershell: |

   git clone https://{PAT for C1/P1}@dev.azure.com/{org}/{proj}/_git/EmptyTestYaml

   cd EmptyTestYaml #cd the code folder

   git remote set-url origin https://{PAT for C2/P1}@dev.azure.com/{org}/{proj}/_git/CrossMicRepo2

   git push -u origin --all -q

  displayName: 'PowerShell Script'

3, Click the Triggers Tab to Enable continuous integration. So that with above steps. the C1/P1 will be automatically synced to C2/P1 when any changes committed to C1/P1.

If C2 does not have to have the source code in its C2/P1, for C1/P1 is open to all with correct credentials. C2 can just create its pipeline with the source code repo pointing to C1/P1. In this way, the C1/P1 source code doesnot have to be synced to C2/P1, and C2 can still validate the development each day against its own Azure pipeline.

Below is the detailed steps to configure the source repo of C2/P1 pipeline to C1/P1.

1, From the C2/P1 pipeline edit page, Click get Source and Choose Other Git, Click New service connection(Or add connection if not configured before).

2, In the prompted window, enter the azure repo url of C1/P1 and PAT for C1/P1.

3, Then Click the Triggers Tab to Enable continuous integration. Then when any changes commited to C1/P1, pipeline of C2/P1 will get triggered.

You can also add the service connection from the Project setting page of C2/P1. Check here for details

Hope above helps!

这篇关于Git:定期将一个回购复制到公司外部无法访问的另一个回购中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 17:12