Gitlab repo sync

Pipeline

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
stages:
  - sync

github_sync:
  stage: sync
  image: alpine:latest
  before_script:
    - apk add git
  script:
    - git clone --mirror https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPO} ./repo/
    - cd repo
    - git remote set-url --push origin "https://oauth2:${PROJECT_PUSH_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
    - git push --verbose --mirror
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"

Variables & Config

Will need to setup a scheduler for the newly created pipeline

Projects -> [PROJECT_NAME] -> Build -> Pipeline schedules -> New schedule

Set “Description, Interval pattern” and the 2 variables

GITHUB_REPO
If your repo link looks like https://github.com/test/repo1.git then you need to grab the part after the github.com
Example: test/repo.git

PROJECT_PUSH_TOKEN
Need to generate an API token on Github which has repo scope

Profile -> Settings -> Developer settings -> Personal access tokens -> Tokens (classic)
All rights reserved