How to share folder with host when using `gitlab-runner` with docker?

2.1k views Asked by At

On a Linux system I am running a simple test job from the command line using the following command:

gitlab-runner exec docker --builds-dir /home/project/buildsdir test_job 

with the following job definition in .gitlab-ci.yml:

test_job:
  image: python:3.8-buster
  script:
    - date > time.dat 

However, the build folder is empty. after having run the job. I only can imaging that build-dir means a location inside the docker image.

Also after having run the job successfully I am doing

docker image ls

and I do not see a recent image.

So how can I "share"/"mount" the actual build folder for the docker gitlab job to the hosts system so I can access all the output files?

I looked at the documentation and I found nothing, the same for

gitlab-runner  exec docker --help 

I also tried to use artifcats

test_job:
  image: python:3.8-buster
  script:
    - pwd
    - date > time.dat 
  artifacts:
    paths:
      - time.dat

but that also did not help. I was not able to find the file time.dat anywhere after the completion of the job.

I also tried to use docker-volumes:

gitlab-runner exec docker --docker-volumes /home/project/buildsdir/:/builds/project-0 test_job
gitlab-runner exec docker --docker-volumes /builds/project-0:/home/project/buildsdir/ test_job

but neither worked (job failed in both cases).

2

There are 2 answers

0
Compholio On

You need to volume-mount the primary "/builds" directory, using your example:

gitlab-runner exec docker --docker-volumes /home/project/buildsdir:/builds test_job

gitlab-runner generates a number of directories inside "/builds", but I don't believe that you can actually mount these directories because of the way that gitlab-runner builds the directory tree.

0
AudioBubble On

you have to configure your config.toml file located at /etc/gitlab-runner/

here's the doc: https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section

first add a build_dir and mention it in the volumes at the end bind it with a directory on your host machine like this:

build_dir = "(Your build dir)"
[runners.docker]
   volumes = ["/tmp/build-dir:/(build_dir):rw"]