Predefined variables:
https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
Variable precedence:
Setup a runner from Gitlab UI:
Register a docker runner:
sudo gitlab-runner register -n \ --url https://gitlab.com/ \ --registration-token REGISTRATION_TOKEN \ --executor docker \ --description "My Docker Runner" \ --docker-image "docker:19.03.12" \ --docker-privileged \ --docker-volumes "/certs/client"
sudo gitlab-runner register \ --non-interactive \ --url "https://gitlab.com/" \ --registration-token "PROJECT_REGISTRATION_TOKEN" \ --executor "docker" \ --docker-image alpine:latest \ --description "docker-runner" \ --tag-list "docker,aws" \ --run-untagged="true" \ --locked="false" \ --access-level="not_protected"
More info: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-socket-binding
Use the runner to push microservice images (using tag to choose runner):
build image: image: docker:stable stage: build variables: CONTAINER_BUILD_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA tags: - docker before_script: - docker info script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker build -t $CONTAINER_BUILD_IMAGE . - docker push $CONTAINER_BUILD_IMAGE when: manual # only: # - schedules
More info: https://gitlab-core.us.gitlabdemo.cloud/ci-cd-training/gitlab-ci-cd-hands-on/-/snippets/433
CI_REGISTRY_IMAGE=gitlab-core.us.gitlabdemo.cloud:5050/iuecytjr/johnzsproject
CI_COMMIT_SHORT_SHA=25bbfbbb
CI_REGISTRY_USER=gitlab-ci-token
CI_REGISTRY=gitlab-core.us.gitlabdemo.cloud:5050
Gitlab-runner debug:
gitlab-runner --debug run