Skip to content

Docs feedback: Using variable interpolation in .gitlab-ci.yml doesn't work

https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#container-registry-examples provides the following example:

services:
  - docker:dind

variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_DRIVER: overlay2
  IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG

before_script:
  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

build:
  stage: build
  script:
    - docker build -t $IMAGE_TAG .
    - docker push $IMAGE_TAG

However if you actually use it your build will fail with (echo statements added to show the problem):

Running with gitlab-runner 11.11.0 (6c154264)
  on My Docker Runner srMa1eEy
Using Docker executor with image docker:stable ...
Pulling docker image docker:stable ...
Using docker image sha256:af42f41a7d73a4a181843011f62cbdefa6d0f546bc7b50f71163750e0475a928 for docker:stable ...
Running on runner-srMa1eEy-project-316-concurrent-0 via yang...
Reinitialized existing Git repository in /builds/grandhome/rapidsales/.git/
Fetching changes...
From https://git.applover.pl/grandhome/rapidsales
   882bfeb..a5bf434  master     -> origin/master
Checking out a5bf434f as master...

Skipping Git submodules setup
$ docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
$ echo $CI_REGISTRY_IMAGE
git.applover.pl:4567/grandhome/rapidsales
$ echo $CI_COMMIT_REF_SLUG
master
$ echo $IMAGE_TAG

$ docker build -f Dockerfile.production -t $IMAGE_TAG  .
invalid argument "." for "-t, --tag" flag: invalid reference format
See 'docker build --help'.
ERROR: Job failed: exit code 125