Skip to content
Snippets Groups Projects
user avatar
Pierre Smeyers authored
69a66605
History
user avatar 69a66605

GitLab Copy CLI

This project provides a CLI tool able to recursively copy/synchronize a GitLab group from one GitLab server to another.

Install

gitlab-cp requires Python 3.11 or higher and can be installed with the following command:

pip install gitlab-cp --index-url https://gitlab.com/api/v4/projects/56596421/packages/pypi/simple

# obtain help
gitlab-cp --help

Usage

usage: gitlab-cp [-h] [--src-api SRC_API] [--src-token SRC_TOKEN] [--src-sync-path SRC_SYNC_PATH] [--dest-api DEST_API] [--dest-token DEST_TOKEN] [--dest-sync-path DEST_SYNC_PATH] [--max-visibility {public,internal,private}] [--exclude EXCLUDE] [--insecure]
                 [--update-release] [--update-avatar] [--no-group-description] [--no-project-description] [--dry-run] [--halt-on-error] [--cache-dir CACHE_DIR]

This tool recursively copies/synchronizes a GitLab group from one GitLab server to another.

options:
  -h, --help            show this help message and exit
  --src-api SRC_API     GitLab source API
  --src-token SRC_TOKEN
                        GitLab source token (optional if source GitLab group and sub projects have `public` visibility)
  --src-sync-path SRC_SYNC_PATH
                        GitLab source root group path to synchronize
  --dest-api DEST_API   GitLab destination API
  --dest-token DEST_TOKEN
                        GitLab destination token with at least scopes `api,read_repository,write_repository` and `Owner` role
  --dest-sync-path DEST_SYNC_PATH
                        GitLab destination root group path to synchronize (defaults to --src-sync-path)
  --max-visibility {public,internal,private}
                        maximum visibility of projects in destination group
  --exclude EXCLUDE     project/group path to exclude from processing (relative to --src-sync-path)
  --insecure            skip SSL verification
  --update-release      force the update of the latest release
  --update-avatar       force update the avatar images even when they exist and look the same
  --no-group-description
                        don't synchronize group description
  --no-project-description
                        don't synchronize project description
  --dry-run             dry run (don't execute any write action)
  --halt-on-error       halt synchronizing whenever an error occurs
  --cache-dir CACHE_DIR
                        cache directory (used to download resources such as images and Git repositories)
CLI option Env. Variable Description
--src-api $SRC_GITLAB_API GitLab source API url (mandatory)
--src-token $SRC_TOKEN GitLab source token (optional if source GitLab group and sub projects have public visibility)
--src-sync-path $SRC_SYNC_PATH GitLab source root group path to synchronize (mandatory)
--dest-api $DEST_GITLAB_API GitLab destination API url (mandatory)
--dest-token $DEST_TOKEN GitLab destination token with at least scopes api,read_repository,write_repository and Owner role (mandatory)
--dest-sync-path $DEST_SYNC_PATH GitLab destination root group path to synchronize (defaults to --src-sync-path)
--max-visibility $MAX_VISIBILITY maximum visibility of projects in destination group (defaults to public)
--exclude $EXCLUDE project/group path(s) to exclude (multiple CLI option; env. variable is a coma separated list)
--insecure $INSECURE skip SSL verification
--update-release $UPDATE_RELEASE set to force the update of the latest release (in order to trigger GitLab CI/CD catalog publication)
--update-avatar $UPDATE_AVATAR force update the avatar images even when they exist and look the same
--no-group-description $GROUP_DESCRIPTION_DISABLED don't synchronize group description
--no-project-description $PROJECT_DESCRIPTION_DISABLED don't synchronize project description
--dry-run none dry run (don't execute any write action)
--halt-on-error none halt synchronizing when an error occurs
--cache-dir $CACHE_DIR cache directory (used to download resources such as images and Git repositories) (defaults to .work)

Developers

gitlab-cp is implemented in Python and relies on Poetry for its packaging and dependency management.

# install dependencies
poetry install

# run from code
poetry run gitlab-cp \
  --src-api https://gitlab.com/api/v4 \
  --src-sync-path to-be-continuous \
  --dest-api https://my.gitlab.host/api/v4 \
  --exclude samples \
  --exclude custom \
  --dest-token $MY_GITLAB_TOKEN