Files
gitlab-ci/git_push_mirror/.gitlab-ci.yml

29 lines
1.1 KiB
YAML

.git_push_mirror:
image: alpine:latest
stage: sync
before_script:
- apk update
- apk add git
script:
- if [ "0$GIT_SYNC_URL" == "0"]; then echo "[ERROR] you must define variable GIT_SYNC_URL for mirroring this repository."; fi
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/$CI_PROJECT_PATH --mirror $CI_PROJECT_NAME
- cd $CI_PROJECT_NAME
- git remote add destination $GIT_SYNC_URL
- echo "https://gitlab.com/ $CI_PROJECT_PATH / $CI_PROJECT_NAME .git"
- git push destination --mirror
artifacts:
expire_in: 1 day
rules:
- if: '$JOB_STOP_GIT_PUSH_MIRROR'
when: never
- if: '$CI_COMMIT_TAG && $GIT_SYNC_URL != null'
when: always
- if: '$CI_COMMIT_BRANCH == "master" && $GIT_SYNC_URL != null &&
( $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "pipeline")'
- if: '$CI_COMMIT_BRANCH == "development" && $GIT_SYNC_URL != null &&
( $CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "pipeline")'
when: always
- when: never