Use of $CI_COMMIT_REF_NAME produces a docker tag set to: none

Summary

When using $CI_COMMIT_REF_NAME in docker image tag naming in gitlab-ci.yml, then it produces a docker image with <none> tag.

Steps to reproduce and current bug behavior

In gitlab-ci.yml, we some variables for docker build and push steps.

variables:
  IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
  IMAGE_LATEST_TAG: $CI_REGISTRY_IMAGE:latest

build-docker:
  stage: build
  before_script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
  script:
    - docker build -t $IMAGE_TAG .
    - docker push $IMAGE_TAG
  only:
    - dev

Using IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME produces a docker image with <none> tag. Here are details of docker images console list print:

  • REPOSITORY: gitlab.mywebsite.com/project/web-client
  • TAG: none
  • IMAGE ID: 5ab29be112af
  • CREATED: 8 hours ago
  • SIZE: 15.9 MB

As you can note, it doesn't use the branch name (dev).

Please note setting a tag manually works as expected:

IMAGE_LATEST_TAG: $CI_REGISTRY_IMAGE:latest produces

gitlab.mywebsite.com/project/web-client:latest

What is the expected correct behavior?

According to documentation, we need to be able to use $CI_COMMIT_REF_NAME variable to tag a docker image with branch name for example (in our case, dev).

https://docs.gitlab.com/ce/ci/docker/using_docker_build.html#using-the-gitlab-container-registry

In this part of documentation, here is the statement:

Here, $CI_REGISTRY_IMAGE would be resolved to the address of the registry tied to this project, and $CI_COMMIT_REF_NAME would be resolved to the branch or tag name for this particular job. We also declare our own variable, $IMAGE_TAG, combining the two to save us some typing in the script section.

and the according gitlab-ci configuration shown as demonstration, which is the same as our own configuration:

variables:
  IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME

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

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info
System information
System:         Ubuntu 16.04
Current User:   git
Using RVM:      no
Ruby Version:   2.3.3p222
Gem Version:    2.6.6
Bundler Version:1.13.7
Rake Version:   10.5.0
Redis Version:  3.2.5
Git Version:    2.11.1
Sidekiq Version:5.0.0

GitLab information Version: 9.2.5 Revision: 6f2e590 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql Using LDAP: no Using Omniauth: no

GitLab Shell Version: 5.0.4 Repository storage paths:

  • default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git

Results of GitLab application Check

Expand for output related to the GitLab application check

Checking GitLab Shell ...

GitLab Shell version >= 5.0.4 ? ... OK (5.0.4) Repo base directory exists? default... yes Repo storage directories are symlinks? default... no Repo paths owned by git:root, or git:git? default... yes Repo paths access is drwxrws---? default... yes hooks directories in repos are links: ... 2/2 ... ok 2/4 ... ok 2/5 ... ok 5/47 ... ok 2/48 ... ok 2/49 ... ok 2/50 ... ok 1/51 ... ok Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Access to /var/opt/gitlab/.ssh/authorized_keys: OK Send ping to redis server: OK gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Reply by email ...

Reply by email is disabled in config/gitlab.yml

Checking Reply by email ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Git configured with autocrlf=input? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config outdated? ... no Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory setup correctly? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) projects have namespace: ... 2/2 ... yes 2/4 ... yes 2/5 ... yes 5/47 ... yes 2/48 ... yes 2/49 ... yes 2/50 ... yes 1/51 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.1.0 ? ... yes (2.3.3) Your git bin path is "/opt/gitlab/embedded/bin/git" Git version >= 2.7.3 ? ... yes (2.11.1) Active users: 4

Checking GitLab ... Finished

Other environment information

Expand for docker info output
Containers: 28
 Running: 0
 Paused: 0
 Stopped: 28
Images: 51
Server Version: 17.03.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.20-std-1
Operating System: Ubuntu 16.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.857 GiB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Expand for gitlab runner info
Version:      9.2.0
Git revision: adfc387
Git branch:   9-2-stable
GO version:   go1.7.5
Built:        Mon, 22 May 2017 16:00:24 +0000
OS/Arch:      linux/amd64