1

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?

2
  • Why not put the file in a package and have your CI/CD process consume the package? Commented Jun 22, 2019 at 13:35
  • @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 file Commented Jun 22, 2019 at 17:35

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

7 Comments

Brilliant. Let me understand what you did. I only need to sync one file NOT the all repo.
@developer9969 Yea, in my example I sync only one file :)
@Abramczyk. Just tried .grr "Get error "The term 'Agent.BuildDirectory' is not recognized as the name" (I should not be getting this error) I am using a release pipeline agent "Hosted Windows 2019 with VS2019".mmm
@developer9969 The variable is for build pipeline, not for Release, why do you use release pipeline?
@Abramczyk .Sorry switched to build and getting further... I omitted git checkout branch-name as its master Is git config for email and user (required) i guess is the "target repo.correct?. Get error not sure why. I error + git commit -m "Sync test.txt" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.