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

╄→гoц情女王★ 提交于 2020-01-01 05:34:07

问题


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/....


回答1:


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


来源:https://stackoverflow.com/questions/39004369/how-do-i-mount-a-volume-in-a-docker-container-in-gitlab-ci-yml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!