Skip to content

GitLab

Published On:
Feb 8, 2014
Last Updated:
Aug 29, 2019

Container Registries

Each repo can have it’s own container registry. You can use this to store Docker images relating to the project.

CI_REGISTRY_IMAGE is provided and is the base path for the container registry.

You can log into the repo’s container registry inside a pipeline with the command:

Terminal window
echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin

Then you be able to push a built image:

Terminal window
docker push "$CI_REGISTRY_IMAGE"

You can download images from the GitLab container registry to your local machine by first logging in:

Terminal window
docker login registry.gitlab.com

You will be prompted to enter your username and password. If you have 2FA enabled, you will have to substitute your password with a personal access token.

You can then download and run an image with:

Terminal window
docker run -it registry.gitlab.com/<org_name>/<project_path> bash

Includes

You can include files in your .gitlab-ci.yml file with the include keyword. This is useful for sharing common configuration between multiple projects.

include:
- project: 'my-group/my-project'
file: '/path/to/file.yml'

You can also use the ref to specify a branch, tag or commit SHA when including a file. This is good for “version control” of your include dependencies.

include:
- project: 'my-group/my-project'
ref: 'main' # Branch name
file: '/path/to/file.yml'
- project: 'my-group/my-project'
ref: 'v1.0.0' # Tag name
file: '/path/to/file.yml'
- project: 'my-group/my-project'
ref: 'b6901dcb0918db67a81b190d24fa67f0b5f99fdb' # Commit SHA
file: '/path/to/file.yml'