简体   繁体   中英

How do I mount a volume in a docker container in .gitlab-ci.yml?

I'm using .gitlab-ci.yml and docker as a GitLab CI runner on an Android project. At the end of the test run, gradlew saves test results in xml and html under the build directory:

Finished generating test XML results (0.001 secs) into: /builds/org/project/sdk/build/test-results/release
 Generating HTML test report...
Finished generating test html results (0.002 secs) into: /builds/org/project/sdk/build/reports/tests/release

I'd like to have access to these files, but the documentation doesn't mention how to mount a volume like one would with docker run -v <path>:/builds/org/... .

I would advice against mounting volumes from the host for your CI. If you really want to, you have to configure the runner accordingly ( config.toml ). If you are using shared runners you never know on what system a particular build is going to be executed.

I think the better solution would be to define the test-results as artifacts .

That way, the test-results are available for older builds and not only the latest build.

Below you can find the configuration ( config.toml ) of my runner I use for building docker-images. You can replace /var/run/docker.sock by the directory you want your build-results to end up in.

[[runners]]
  name = "Docker"
  url = "https://mygitlab/ci"
  token = "mytoken"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:latest"
    privileged = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
  [runners.cache]
    Insecure = false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM