inspired by https://gitlab.com/freifunkks/mirror-scripts
This can be used, for example, to clone a repository living on github over to GitLab in order to run CI
-
Setup separate repository with mirror scripts. We'll call it "mirror-scripts"
-
push the two files below.
- in the
.gitlab-ci.yml
replaceMY_REPO
with your repo name - replace
MY_USERNAME
with your username - you can add multiple repos to mirror by copying the mirror job
- in the
-
generate an SSH key.
- Put the private key into a variable called
SSHKEY_PROJECT1
on the mirror-scripts repo. - put the public key as deploy key into the source repo
- put the public key as a write-enabled deploy key into the target repo
- Put the private key into a variable called
-
in gitlab settings for the mirror-scripts repo:
- enable pipelines
- add a pipeline trigger hook. Note the token.
- Also note the numeric project id. You can find it in the documentation snippet below the pipeline trigger settings.
-
in the settings of the source repo:
- add a webhook with this url:
https://gitlab.com/api/v4/projects/PROJECT_ID/ref/master/trigger/pipeline?token=TOKEN
- replace
PROJECT_ID
andTOKEN
with the values from above - set the webhook to run on push
- add a webhook with this url:
for more repos (ex PROJECT2
):
- copy the block
mirror-PROJECT1
ingitlab-ci.yml
and replacePROJECT1
byPROJECT2
- generate a new SSH key
- configure it for the source and target repo
- put it into a variable called
SSHKEY_PROJECT2
done!