1
votes

I have file that I need to keep in sync between 2 repos (2 different organizations)

  1. https://[email protected]/org1/XProject/_git/MyRepoX
  2. https://[email protected]/org2/YProject/_git/MyRepoY

Both RepoX and RepoY have a file in common "FileA" (to keep in sync)

When a change occurs FileA -Trigger pipeline and "Merge" MyRepoX/FileA into MyRepoY/FileA

I have done the following:

  • Created a PAT token from Org1
  • Created a PAT token from Org2
  • Created pipeline with cmdline script
  • In the script I did:

    • git clone https://@dev.azure.com/org1/XProject/_git/MyRepoX
    • git merge https://@dev.azure.com/org1/YProject/_git/MyRepoY

Error "Nothing to merge".

I am a "git novice" what command do I need to do to keep a file in sync between repos?

1
Why not put the file in a package and have your CI/CD process consume the package?Daniel Mann
@DanielMann Could you expand a bit more I did not think of it.The all thing must happen on commit of a change of the filedeveloper9969

1 Answers

1
votes

You can't just do the merge like you did because it's 2 different repositories, also, do you really want to merge the whole repo? you need only one file to sync.

You can make it happen with this logic:

  • Clone the second repo
  • Copy FileA from repo 1 to repo 2
  • Commit & Push

I wrote a small PowerShell script that works:

cd $(Agent.BuildDirectory)
git clone https://[email protected]/{organzition}/{project}/_git/{repo-name}
cd {repo-name}
git checkout branch-name # if the synced file not in master
# Assuming the synced file name is "test.txt" and he exists in the folder "common"
Copy-Item $(Build.SourcesDirectory)\common\test.txt $(Agnet.BuildDirectory)\{repo-name}\common -Force
# If you use Hosted agent you need to configure the email & address
git config --globa user.email "[email protected]" 
git config --global user.name "Azure DevOps Build"
git add common/test.txt
git commit -m "Sync test.txt"
git push

Now create 2 pipelines, in each pipelines do the trigger only the common file you want to sync:

enter image description here

With the above script:

enter image description here

Results:

enter image description here

enter image description here