bachp/git-mirror

Sync/mirror single file in Gitlab periodically between 2 different repositories

Closed this issue · 3 comments

Hi,

We're trying to sync a single file from Project A to Project B in our Gitlab CI. We tried using webhooks but looks like it is for sending notifications for single group/project and not for a specific file.

We also tried to configure emails alerts from "Settings->Integrations->Emails on push" but it only notifies us about the change done on specific file in source Project A.

We were able to achieve mirroring across these repos but thats going to sync my complete projects from source to destination but my requirement is to sync only one file.

Can you please let us know in Gitlab CI (version 15.11.8) if there is any way/feature to sync a single file from source project (ex Project A) to destination project (ex Project B) so that whenever there is a change in the file under Project A that file gets automatically synched in Project B

Appreciate your feedback/help

bachp commented

@steward93 Syncing a single file is out of scope for this project.

If this is only a one-way sync, you are after this might be achievable with some simple scripting. Steps would be

  1. Clone Project A and Project B into you CI job
  2. Copy desired file from A to B
  3. Commit and push project B

@bachp Thank you for your response. Tried the steps you mentioned and it needed a gitlab token to push it to the repo. Having said that CI job which is created needs to be triggered manually every time to push that single file to project B after checking if there are any changes in Project A.

So as I need to sync this file periodically (every time it gets changed by owner of project A should be synched with Project B for which am the owner) thought of if there was any way to sync single file automatically by pull mirror mechanism ? like how pull mirroring happens for entire files/folders in a repo(this works and tested ok for my projects)

bachp commented

@steward93 For push mirroring the easiest is to run a CI job on push to the source repository.

For pull mirroring you could maybe negociate with the source owner to crate a downstream job, or you can run a scheduled job on your destination repo and do it in a polling fashion.

Closing this issue as it is not a bug.