如何在.gitlab-ci.yml中的Docker容器中装载卷? [英] How do I mount a volume in a docker container in .gitlab-ci.yml?

查看:105
本文介绍了如何在.gitlab-ci.yml中的Docker容器中装载卷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 .gitlab-ci.yml 和docker作为Android项目上的GitLab CI运行器。在测试运行结束时, gradlew 将测试结果保存在build目录下的xml和html中:

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

我想访问这些文件,但是文档没有提到如何像使用 docker run -v< path>:/ builds / org /...那样装入卷。 / p>

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

推荐答案

我建议不要从主机上为您的CI装入卷。
如果确实需要,则必须相应地配置运行器( config.toml )。
如果您使用共享运行器,则您永远不知道要在哪个系统上执行特定的构建。

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.

在下面,您可以找到我用来构建docker-images的运行程序的配置( config.toml )。您可以将 /var/run/docker.sock 替换为您要结束生成结果的目录。

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

这篇关于如何在.gitlab-ci.yml中的Docker容器中装载卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆