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
| Name | required | type | Hints |
|---|---|---|---|
| GITLAB_TOKEN | optional | string | Is a GitLab Token |
| GIT_SSH_KEY | optional | file | Is a SSH Key. Use when there is no token |
Setup
Choice 1: Use GitLab Token
- Add the CI Variable
GITLAB_TOKENas 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_KEYas 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_KEYof 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
| Name | Description | Default | Type |
| --- | --- | --- | --- |
| custom-script | Custom script to run in addition to the default mirroring script. | string | |
| destination | The destination repository to mirror to like git@git.example.com:xrow-public/ci-tools.git. | string | |
| git-token | The token to be used. Provide the variable name. | GITLAB_TOKEN | string |
| name | git | string | |
| needs | The jobs that this job depends on. | [] | array |
| rules | The 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 |
| source | The source repository to mirror. Like https://gitlab.com/xrow-public/ci-tools.git | string | |
| ssh-private-key | The ssh key to be used. Provide the variable name as file. | GIT_SSH_KEY | string |
| stage | The pipeline stage that the jobs belongs to. | deploy | string |