Skip to main content

GIT Mirror component

Makes a bare clone and mirrors the result to the destination. Can allow customization during mirroring.

For token-based authentication, configure GITLAB_TOKEN with a group service account.

Variables​

NamerequiredtypeHints
GITLAB_TOKENoptionalstringIs a GitLab Token
GIT_SSH_KEYoptionalfileIs a SSH Key. Use when there is no token

Setup​

Choice 1: Use GitLab Token​

  • Add the CI Variable GITLAB_TOKEN as string with the access token to the destination repository.

Choice 2: Use SSH Key​

  • Setup a Deploy Key with access to the destination repository.
  • Add the CI Variable GIT_SSH_KEY as file with the access key to the destination repository.

Usage​

  • Create GitLab pipeline file .gitlab-ci.yml:
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/git-mirror@stable
inputs:
source: https://gitlab.com/xrow-public/ci-tools.git
destination: git@git.example.com:xrow-public/ci-tools.git

Generate a GitLab SSH Key​

GIT_SSH_KEY is a variable that can be used in pipelines with certain components to authenticate with GitLab using SSH keys for git operations.

To generate a GitLab SSH key, you can follow these steps:

  • Execute the following command in your terminal to generate a new SSH key pair:
tmp_dir=$(mktemp -d)
ssh-keygen -t ed25519 -f $tmp_dir/your-key-filename -C "gitlab-deployment-key" -N ""
echo "Public Deployment key:"
cat $tmp_dir/your-key-filename.pub
echo "Private Deployment key:"
cat $tmp_dir/your-key-filename
  • Create a variable GIT_SSH_KEY of type file in your GitLab project and paste the private key content into it. Make sure to mark it as a file variable.
  • Add the public key as a deploy key in your GitLab repository with write access.

Inputs​

NameDescriptionDefaultType
------------
custom-scriptCustom script to run in addition to the default mirroring script.string
destinationThe destination repository to mirror to like git@git.example.com:xrow-public/ci-tools.git.string
git-tokenThe token to be used. Provide the variable name.GITLAB_TOKENstring
namegitstring
needsThe jobs that this job depends on.[]array
rulesThe rules that this job depends on.[{"if":"$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && ( $CI_PIPELINE_SOURCE == \"push\" || $CI_PIPELINE_SOURCE == \"web\" || $CI_PIPELINE_SOURCE == \"schedule\" )","when":"on_success"},{"when":"never"}]array
sourceThe source repository to mirror. Like https://gitlab.com/xrow-public/ci-tools.gitstring
ssh-private-keyThe ssh key to be used. Provide the variable name as file.GIT_SSH_KEYstring
stageThe pipeline stage that the jobs belongs to.deploystring