Skip to content

gitlab/gitlab-runner:alpine alternates between users at (seemingly) random

Summary

Runnning my .gitlab-ci.yml with the docker gitlab-runner ends up having 2 different users execute scripts.

Steps to reproduce

Create a .gitlab-ci.yml file that looks like this:

stages:
  - a
  - b
  - c
  - easy
  - as
  - one
  - two
  - three

a:
  stage: a
  script:
    - "echo Running as $(whoami)"
    
b:
  stage: b
  script:
    - "echo Running as $(whoami)"
    
c:
  stage: c
  script:
    - "echo Running as $(whoami)"
    
d:
  stage: easy
  script:
    - "echo Running as $(whoami)"
e:
  stage: as
  script:
    - "echo Running as $(whoami)"
f:
  stage: one
  script:
    - "echo Running as $(whoami)"
g:
  stage: two
  script:
    - "echo Running as $(whoami)"
h:
  stage: three
  script:
    - "echo Running as $(whoami)"

Set up an alpine runner using docker

docker pull gitlab/gitlab-runner:alpine
docker run -d --name foo --rm -v //var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:alpine
docker exec -ti foo gitlab-runner --debug register
# http://url.to.gitlab.com:port123456
# token: 1234567890
# name: foo
# tags: NA
# untagged build: true
# locked runner: false
# executor: SHELL
# (Match others to your gitlab instance but make sure to select the SHELL executor)
docker exec -ti foo gitlab-runner --debug run

Then kick off a pipeline.

Actual behavior

Going into each job on the pipeline that is started, you'll see that some are run as the user gitlab-runner, while others are run as root. I haven't been able to discern a pattern yet. Sometimes it's every other, other times it's every 2.

Expected behavior

I would expect them to all be run as a single user. Whether it should be root or gitlab-runner I'm not sure; but after taking a look at the gitlab-runner:alpine image it looks like it should be gitlab-runner.

Relevant logs and/or screenshots

image

(A)
Running with gitlab-runner 10.6.0 (a3543a27)
  on bar 5d8230e7
Using Shell executor...
Running on 7921e980cf94...
Cloning repository...
Cloning into '/home/gitlab-runner/builds/5d8230e7/0/h/showcase'...
Checking out 81b0e960 as master...
Skipping Git submodules setup
$ echo Running as $(whoami)
Running as gitlab-runner
Job succeeded

(B)
Running with gitlab-runner 10.6.0 (a3543a27)
  on bar 5d8230e7
Using Shell executor...
Running on 7921e980cf94...
Cloning repository...
Cloning into '/builds/5d8230e7/0/h/showcase'...
Checking out 81b0e960 as master...
Skipping Git submodules setup
$ echo Running as $(whoami)
Running as root
Job succeeded

(C)
Running with gitlab-runner 10.6.0 (a3543a27)
  on bar 5d8230e7
Using Shell executor...
Running on 7921e980cf94...
Fetching changes...
HEAD is now at 81b0e96 Update .gitlab-ci.yml
Checking out 81b0e960 as master...
Skipping Git submodules setup
$ echo Running as $(whoami)
Running as root
Job succeeded

(Easy)
Running with gitlab-runner 10.6.0 (a3543a27)
  on bar 5d8230e7
Using Shell executor...
Running on 7921e980cf94...
Fetching changes...
HEAD is now at 81b0e96 Update .gitlab-ci.yml
Checking out 81b0e960 as master...
Skipping Git submodules setup
$ echo Running as $(whoami)
Running as gitlab-runner
Job succeeded

(As)
Running with gitlab-runner 10.6.0 (a3543a27)
  on bar 5d8230e7
Using Shell executor...
Running on 7921e980cf94...
Fetching changes...
HEAD is now at 81b0e96 Update .gitlab-ci.yml
Checking out 81b0e960 as master...
Skipping Git submodules setup
$ echo Running as $(whoami)
Running as root
Job succeeded

(One)
Running with gitlab-runner 10.6.0 (a3543a27)
  on bar 5d8230e7
Using Shell executor...
Running on 7921e980cf94...
Fetching changes...
HEAD is now at 81b0e96 Update .gitlab-ci.yml
Checking out 81b0e960 as master...
Skipping Git submodules setup
$ echo Running as $(whoami)
Running as root
Job succeeded

(Two)
Running with gitlab-runner 10.6.0 (a3543a27)
  on bar 5d8230e7
Using Shell executor...
Running on 7921e980cf94...
Fetching changes...
HEAD is now at 81b0e96 Update .gitlab-ci.yml
Checking out 81b0e960 as master...
Skipping Git submodules setup
$ echo Running as $(whoami)
Running as gitlab-runner
Job succeeded

(Three)
Running with gitlab-runner 10.6.0 (a3543a27)
  on bar 5d8230e7
Using Shell executor...
Running on 7921e980cf94...
Fetching changes...
HEAD is now at 81b0e96 Update .gitlab-ci.yml
Checking out 81b0e960 as master...
Skipping Git submodules setup
$ echo Running as $(whoami)
Running as root
Job succeeded

Environment description

Host: Windows 10 Enterprise

Docker version 18.03.0-ce-rc4, build fbedb97

GitLab Community Edition 10.5.4 8d768f9

bash-4.4# gitlab-runner --version
Version:      10.6.0
Git revision: a3543a27
Git branch:   10-6-stable
GO version:   go1.9.4
Built:        2018-03-22T08:34:11+00:00
OS/Arch:      linux/amd64
Edited by ~P