Skip to content

`gitlab-ci-multi-runner exec docker build` doesn't run before_script

My .gitlab-ci.yaml:

.ruby: &ruby
  stage: build
  image: 'ruby:2.2.2'
  before_script:
  - export RUBYGEMS_URL=${RUBYGEMS_URL:=https://xxx/}
  - echo -e "---\nsources:\n- $RUBYGEMS_URL" > ~/.gemrc
  - gem install bundler
  - bundle config mirror.https://rubygems.org $RUBYGEMS_URL
  - bundle config jobs 20
  - bundle config retry 5

rails_spec_virtsimple:
  <<: *ruby
  services:
  - postgres:9.4
  - redis
  script:
  - export VIRTKICK_MODE=organization
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install --without development
  - bundle exec rake db:migrate

Execution log. We can clearly see the first command is export VIRTKICK_MODE=organization from script, not export RUBYGEMS_URL from before_script.

nowaker@nwkr-desktop ~/projekty/virtkick/test/virtkick-webapp (git)-[master] % BUCKET=`basename $(pwd)`; mkdir -p ~/projekty/cache/minio-amazon-s3/"$BUCKET"; gitlab-ci-multi-runner exec docker --docker-pull-policy never --cache-type s3 --cache-s3-access-key 12345 --cache-s3-secret-key 12345678 --cache-s3-insecure --cache-s3-server-address 172.17.0.1:9005 --cache-s3-bucket-name="$BUCKET" --cache-s3-bucket-location us-east-1 --env RUBYGEMS_URL=http://172.17.0.1:9292/ --env VIRTKICK_REDIS_SOCKET=redis://172.17.0.1:6379/1 rails_spec_virtsimple
Running with gitlab-ci-multi-runner dev (HEAD)
Using Docker executor with image ruby:2.2.2 ...
Starting service postgres:9.4 ...
Starting service redis:latest ...
Waiting for services to be up and running...
Running on runner--project-1-concurrent-0 via nwkr-desktop...
Cloning repository...
Cloning into '/builds/project-1'...
done.
Checking out 62a0b84b as master...
Checking cache for rails_spec_virtsimple/master...
$ export VIRTKICK_MODE=organization
$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install --without development
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
...

The same YAML works on GitLab CI. https://gitlab.com/virtkick/virtkick-webapp/builds/3599522

...
Checking cache for rails_spec_virtsimple/master...
$ export RUBYGEMS_URL=${RUBYGEMS_URL:=https://xxx/}
...