.gitlab-ci.yml
파일은 B 저장소 push 에서 제외.gitlab-ci.yml 파일
image: lorisleiva/laravel-docker:latest
stages:
- B_repository_push
release-job:
stage: B_repository_push
before_script:
# 한국시간
- apk add tzdata && cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime && echo "Asia/Seoul" > /etc/timezone
# git push 계정정보
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global http.sslverify "false"
script:
# 토큰 값은 ci/cd 설정에 등록되어 있음
- git clone https://$CLONE_TOKEN@gitlab.siteA.com/foo/app.git A_folder
- git clone https://$PUSH_TOKEN@git.siteB.kr/foo/app.git B_folder
# A저장소와 B저장소 코드동기화
- rsync -a --delete
--exclude='.git'
--exclude='.gitlab-ci.yml'
A_folder/ B_folder/
- cd B_folder
# 불필요한 파일 정리
- rm -f .gitlab-ci.yml
- git add --all
- git commit -m "🚀 `date +'%Y-%m-%d %H:%M:%S'` "
- git push -f
rules:
# .gitlab-ci.yml 파일 수정시 git push 에러나기 때문에 예외처리!
- if: '$CI_COMMIT_REF_NAME == "main"'
changes:
- .gitlab-ci.yml
when: never
# main branch MR시 동작
- if: '$CI_COMMIT_REF_NAME == "main"'
when: always