Gitlab runner not executing jobs docker image

2019-08-03 19:42发布

问题:

I created a minimal gitlab CI script to verify this error:

docker_execution_test:
  image: debian:9

  script:
    - pwd
    - ls

The output I would expect is this:

db@theia:~/git/docker_test (master*)$ docker run -it --rm debian:9 pwd
/
db@theia:~/git/docker_test (master*)$ docker run -it --rm debian:9 ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

However, the output when executed through gitlab-runner is this:

db@theia:~/git/docker_test (master)$ gitlab-runner exec docker docker_execution_test
Runtime platform                                    arch=amd64 os=darwin pid=49585 revision=3afdaba6 version=11.5.0
WARNING: You most probably have uncommitted changes.
WARNING: These changes will not be tested.
Running with gitlab-runner 11.5.0 (3afdaba6)
Using Docker executor with image debian:9 ...
Pulling docker image debian:9 ...
Using docker image sha256:4879790bd60d439cfe39c063660eef7af525d5f6f1cbb701a14c7cfc11cbfcf7 for debian:9 ...
Running on runner--project-0-concurrent-0 via theia.local...
Cloning repository...
Cloning into '/builds/project-0'...
done.
Checking out bb973ec4 as master...
Skipping Git submodules setup
$ pwd
/builds/project-0
$ ls
README.md
Job succeeded

What the job is listing is the content of the special gitlab container that's used throughout the build. Why is the container not created? What am I missing here?

回答1:

As it turns out, gitlab-runner was working as expected. What is quite confusing though is that it does some manipulations to the image it's booting up. The entrypoint is overridden and the folder the repository is checked out into is mounted into the container with the WORKDIR pointing to it.

So while it is possible to run your own images as containers, you have to keep in mind that you might need to change the folder before running any commands.