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

1k Views Asked by At

So I've got 2 repos, kinda like so:

/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. 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.

How can I accomplish this?


Context: I'm using Azure DevOps, where RepoA is in ProjectA, and RepoB is in ProjectB. ProjectA is just for my team's use, while ProjectB is for the rest of the company; RepoB is actually the project wiki for ProjectB. 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.

1

There are 1 best solutions below

2
On BEST ANSWER

Based on your requirement, you need to sync the files in two repos(different project).

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.

Here are the steps:

Step1: Add the extension: Git Tools for Azure DevOps. And you will get the task: Git Publish Task in Pipeline.

Step2: Add Git Publish Task in Pipeline.

enter image description here

The Git Repo url sample:

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

Step3: You need to set the Trigger in Pipeline. enter image description here

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.

If you don't want to use extension, you could try to use Git command to replace the Git Publish task. But it will be a little more complicated