简体   繁体   English

如何使用 Azure 管道将一个存储库中的文件和子目录与另一个存储库中的文件和目录同步?

[英]How to use an Azure pipeline to sync a file and subdirectory in one repo with a file and directory in another repo?

So I've got 2 repos, kinda like so:所以我有 2 个 repos,有点像这样:

/repoA
   /directoryA
     /fileA
     /subdirectoryA
       ...lots of files in here

/repoB
   /directoryB
   /fileB
   ...lots and lots and lots of other directories and files

What I want to do is sync fileA with fileB , and sync all of the contents of subdirectoryA with all the contents of directoryB such that any changes I push to fileA or anything in subdirectoryA will also get pushed by a CI/CD pipeline to the corresponding file or directory in repoB.我想要做的是将fileAfileB同步,并将subdirectoryA的所有内容与directoryB的所有内容同步,这样我推送到fileAsubdirectoryA中的任何内容的任何更改也将被 CI/CD 管道推送到相应的repoB 中的文件或目录。 I don't care about any of the other files or directories in repoB so I'd rather not have them cluttering up my repoA.我不关心 repoB 中的任何其他文件或目录,所以我不想让它们弄乱我的 repoA。

How can I accomplish this?我怎样才能做到这一点?


Context: I'm using Azure DevOps, where RepoA is in ProjectA, and RepoB is in ProjectB.上下文:我正在使用 Azure DevOps,其中 RepoA 在 ProjectA 中,而 RepoB 在 ProjectB 中。 ProjectA is just for my team's use, while ProjectB is for the rest of the company; ProjectA仅供我团队使用,ProjectB供本公司rest使用; RepoB is actually the project wiki for ProjectB. RepoB 实际上是 ProjectB 的项目 wiki。 Rather than physically maintaining our documentation in 2 places or having to go to a separate project to update it (a bottleneck like that means it wouldn't get updated, ever), I want to use an Azure Pipeline to automatically push any documentation changes we make in RepoA over to the wiki in RepoB so that everyone's well-informed and happy.我不想在 2 个地方物理维护我们的文档,也不必将 go 放到一个单独的项目中来更新它(这样的瓶颈意味着它永远不会更新),我想使用 Azure 管道来自动推送我们的任何文档更改将 RepoA 中的 wiki 转移到 RepoB 中的 wiki,以便每个人都消息灵通和快乐。

Based on your requirement, you need to sync the files in two repos(different project).根据您的要求,您需要同步两个 repos(不同项目)中的文件。

There is no out-of-box method could meet your requirements.没有开箱即用的方法可以满足您的要求。

To achieve this goal, you could use the Azure Pipeline to do this operation automatically.为了实现这个目标,您可以使用 Azure 管道自动执行此操作。

Here are the steps:以下是步骤:

Step1: Add the extension: Git Tools for Azure DevOps . Step1:添加扩展: Git Tools for Azure DevOps And you will get the task: Git Publish Task in Pipeline.您将获得任务: Git Publish Task

Step2: Add Git Publish Task in Pipeline. Step2:在管道中添加 Git 发布任务。

在此处输入图像描述

The Git Repo url sample: Git 回购 url 样品:

https://{UserName}:{PAT(Personal Access Token)}@dev.azure.com/{Organization}/{Project}/_git/{RepoName}

Step3: You need to set the Trigger in Pipeline. Step3:您需要在Pipeline中设置Trigger 在此处输入图像描述

You could set the branch and path.您可以设置分支和路径。 When the fileA or the files in the sub folder path are changed, it will trigger this pipeline and the change will be pushed to target repo.当 fileA 或子文件夹路径中的文件发生更改时,会触发此管道并将更改推送到目标 repo。

If you don't want to use extension, you could try to use Git command to replace the Git Publish task.如果您不想使用扩展,可以尝试使用 Git 命令替换 Git 发布任务。 But it will be a little more complicated但是会稍微复杂一些

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM