Variables in docker service alias not supported
Summary
Although the usage of environment variables works (almost?) everywhere in .gitlab-ci.yml files (e.g. cache, artifacts, image, ...), variables are apparently not supported in docker service aliases.
Steps to reproduce
# .gitlab-ci.yml
stages:
- test
test:
stage: test
image: alpine:3.6
services:
- name: mysql:latest
alias: "$EXAMPLE_HOSTNAME"
variables:
EXAMPLE_HOSTNAME: "custom_mysql_hostname"
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
script:
- echo "$EXAMPLE_HOSTNAME"
- cat /etc/hosts
tags:
- docker
Actual behavior
Variables in docker services aliases are apparently not supported - instead the variable name is written to /etc/hosts
as-is.
cat /etc/hosts
[...]
172.17.0.2 mysql 0ed8b29901c4 runner-2e4737f8-project-169-concurrent-0-mysql-0
172.17.0.2 $EXAMPLE_HOSTNAME 0ed8b29901c4 runner-2e4737f8-project-169-concurrent-0-mysql-0
172.17.0.3 runner-2e4737f8-project-169-concurrent-0
Expected behavior
cat /etc/hosts
[...]
172.17.0.2 mysql 0ed8b29901c4 runner-2e4737f8-project-169-concurrent-0-mysql-0
172.17.0.2 custom_mysql_hostname 0ed8b29901c4 runner-2e4737f8-project-169-concurrent-0-mysql-0
172.17.0.3 runner-2e4737f8-project-169-concurrent-0
Relevant logs and/or screenshots
Running with gitlab-ci-multi-runner 9.5.0 (413da38)
on runner.example.net (2e4737f8)
Using Docker executor with image alpine:3.6 ...
Starting service mysql:latest ...
Pulling docker image mysql:latest ...
Using docker image mysql:latest ID=sha256:b4e78b89bcf31a38eab47da1b2b36235462e83beebacb7479d725367e76572cf for mysql service...
Waiting for services to be up and running...
Using docker image sha256:68ca2ef543ca7665db19914e2226b394f1ac85dbfadc6c3e6dc6511974914bbc for predefined container...
Pulling docker image alpine:3.6 ...
Using docker image alpine:3.6 ID=sha256:76da55c8019d7a47c347c0dceb7a6591144d232a7dd616242a367b8bed18ecbc for build container...
Running on runner-2e4737f8-project-169-concurrent-0 via 9631295fbe60...
Fetching changes...
HEAD is now at 4c46c5f Demonstrates issue #2775 - Variables not used in service alias
From https://gitlab.example.net/example/service-alias
+ 4c46c5f...5a34e5d master -> origin/master (forced update)
Checking out 5a34e5d2 as master...
Skipping Git submodules setup
$ echo "$EXAMPLE_HOSTNAME"
custom_mysql_hostname
$ cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 mysql 0ed8b29901c4 runner-2e4737f8-project-169-concurrent-0-mysql-0
172.17.0.2 $EXAMPLE_HOSTNAME 0ed8b29901c4 runner-2e4737f8-project-169-concurrent-0-mysql-0
172.17.0.3 runner-2e4737f8-project-169-concurrent-0
Job succeeded
Used GitLab Runner version
Running with gitlab-ci-multi-runner 9.5.0 (413da38)
on runner.example.net (2e4737f8)
Using Docker executor with image alpine:3.6 ...
Edited by Andreas Erhard