Skip to content

Shell runner fetches repo and removes files before running before_script scripts

Summary

In a shell runner, before_script scripts run after the repo has been fetched and files not part of repo have been removed. These temp files are files needed by the service that should have been stopped with a before_script script. This causes the service to fail and enter a broken state where it won't start correctly from a after_script script.

Steps to reproduce

Specify a before_script to stop a service expecting it to run before anything else especially fetching the repo and removing files.

.gitlab-ci.yml
before_script:
  - sudo /etc/init.d/ezproxy stop
  - sleep 10

after_script:
  - sudo /etc/init.d/ezproxy restart

stages:
  - deploy

variables:

deploy_barbecue:
  stage: deploy
  environment:
    name: DEV
  script:
    - echo "Deploy to $SHORT_ALIAS in env $DEV_Host"
  dependencies:
  tags:
    - DEV

Actual behavior

The repo is fetched and temp files from the running service are removed before the service is stopped.

Commit to branch and results:
Running with gitlab-runner 11.11.2 (ac2a293c)
  on barbecue_ezproxy QscBDzS4
Using Shell executor...
Running on barbecue...
Reinitialized existing Git repository in /opt/gitlab-runner/builds/QscBDzS4/0/ezproxy/ezproxy/.git/
Fetching changes...
From https://gitlab.myserver/ezproxy/ezproxy
   c49d8bd..5973e3e  develop    -> origin/develop
Checking out 5973e3e3 as develop...
Removing SPULog.log <<-- log file that can be removed after service is stopped
Removing ezproxy.log <<-- log file that can be removed after service is stopped
Removing messages.txt <<-- log file that can be removed after service is stopped
Skipping Git submodules setup
$ sudo /etc/init.d/ezproxy stop <<-- also was expecting to see "Running before script..."
$ sleep 10
$ echo "Deploy to $SHORT_ALIAS in env $DEV_Host"
Deploy to alcatraz in env alcatraz
Running after script...
... some other scripts
$ sudo /etc/init.d/ezproxy start
Job succeeded

Expected behavior

I would expect to see:

Commit to branch and results:
Running with gitlab-runner 11.11.2 (ac2a293c)
  on barbecue_ezproxy QscBDzS4
Using Shell executor...
Running on barbecue...
Running before script...
$ sudo /etc/init.d/ezproxy stop
$ sleep 10
Reinitialized existing Git repository in /opt/gitlab-runner/builds/QscBDzS4/0/ezproxy/ezproxy/.git/
Fetching changes...
From https://gitlab.myserver/ezproxy/ezproxy
   c49d8bd..5973e3e  develop    -> origin/develop
Checking out 5973e3e3 as develop...
Removing SPULog.log <<-- log file that can be removed after service is stopped
Removing ezproxy.log <<-- log file that can be removed after service is stopped
Removing messages.txt <<-- log file that can be removed after service is stopped
Skipping Git submodules setup
...and so on

Relevant logs and/or screenshots

See above

Environment description

Specific shell runner on own Linux server with the runner connected to our own deployment of gitlab omnibus.

config.toml contents
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "barbecue_ezproxy"
  url = "https://gitlab.myserver/"
  token = " "
  executor = "shell"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

Used GitLab Runner version

Version:      11.11.2
Git revision: ac2a293c
Git branch:   
GO version:   go1.8.7
Built:        2019-06-03T10:57:49+0000
OS/Arch:      linux/amd64

Possible fixes

~bug

Edited by 🤖 GitLab Bot 🤖