git - gitlab-runner 或 Docker 默认缓存 /builds 目录吗?
问题描述
我在我的 MacBook Pro 上使用 gitlab-runner 和 Docker。我正在使用 gitlab.com 来托管我的 git 存储库。我已将一个存储库配置为在将提交推送到存储库时执行管道。管道有两个工作:显示一些信息,并克隆一个单独的存储库作为依赖项。
这是第一份工作的输出:
Running with gitlab-runner 12.2.0 (a987417a)
on old_gen_runner 6fsjs96e
Using Docker executor with image gcc-arm_4_7-2013q3:3.0 ...
Using docker image sha256:5d4741a428654beb44a3c004822e4d2ceededc88f22ec1ec7f45dedf707a0302 for gcc-arm_4_7-2013q3:3.0 ...
Running on runner-6fsjs96e-project-13664495-concurrent-0 via my_laptop.local...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/staging-fw/my-project/.git/
Created fresh repository.
From https://gitlab.com/staging-fw/my-project
* [new branch] master -> origin/master
Checking out 722c2c38 as master...
Skipping Git submodules setup
$ python /scripts/info.py
Printing job info...
Builds dir: /builds
Commit Message:
Modified yml file.
Branch: master
Project dir: /builds/staging-fw/my-project
$ ls /builds
my-project
这是第二个作业的输出:
Running with gitlab-runner 12.2.0 (a987417a)
on old_gen_runner 6fsjs96e
Using Docker executor with image gcc-arm_4_7-2013q3:3.0 ...
Using docker image sha256:5d4741a428654beb44a3c004822e4d2ceededc88f22ec1ec7f45dedf707a0302 for gcc-arm_4_7-2013q3:3.0 ...
Running on runner-6fsjs96e-project-13664495-concurrent-0 via my_laptop.local...
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/staging-fw/my-project/.git/
Checking out 722c2c38 as master...
Skipping Git submodules setup
$ git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/staging-fw/my-dependencies.git /builds/dependencies
Cloning into '/builds/dependencies'...
Job succeeded
可以看到,第一次创建管道,就成功了。
如果我通过推送新更改再次运行它,这是第一个作业的输出:
Running with gitlab-runner 12.2.0 (a987417a)
on old_gen_runner 6fsjs96e
Using Docker executor with image gcc-arm_4_7-2013q3:3.0 ...
Using docker image sha256:5d4741a428654beb44a3c004822e4d2ceededc88f22ec1ec7f45dedf707a0302 for gcc-arm_4_7-2013q3:3.0 ...
Running on runner-6fsjs96e-project-13664495-concurrent-0 via my_laptop.local...
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/staging-fw/my-project/.git/
From https://gitlab.com/staging-fw/my-project
722c2c3..f321b75 master -> origin/master
Checking out f321b75f as master...
Skipping Git submodules setup
$ python /scripts/info.py
Printing job info...
Builds dir: /builds
Commit Message:
Modified yml file.
Branch: master
Project dir: /builds/staging-fw/my-project
$ ls /builds
my-project
dependencies
Job succeeded
如您所见,dependencies 文件夹还在吗?不仅如此,它不再Initialized empty Git repository
像在第一份工作的第一次运行中那样说,而是现在说Reinitialized existing Git repository
.
以下是第二次运行期间第二个作业发生的情况:
Running with gitlab-runner 12.2.0 (a987417a)
on old_gen_runner 6fsjs96e
Using Docker executor with image gcc-arm_4_7-2013q3:3.0 ...
Using docker image sha256:5d4741a428654beb44a3c004822e4d2ceededc88f22ec1ec7f45dedf707a0302 for gcc-arm_4_7-2013q3:3.0 ...
Running on runner-6fsjs96e-project-13664495-concurrent-0 via my_laptop.local...
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/staging-fw/my-project/.git/
Checking out f321b75f as master...
Skipping Git submodules setup
$ git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/staging-fw/my-dependencies.git /builds/dependencies
fatal: destination path '/builds/dependencies' already exists and is not an empty directory.
ERROR: Job failed: exit code 1
我的问题是:
/builds
是否为 Docker 中的每个单独容器创建了目录?这是我最初的理解,Docker 中的每个容器都有自己独立的 /builds 目录。目录是否
/builds
为所有 Docker 容器共享?我找不到这方面的任何信息。
2a。如果该/builds
目录为所有 Docker 容器共享,那么它在哪里以及是谁创建的?
解决方案
GitLab CI/CD 的默认 Git 策略是“获取”。如果相同的静态运行器一遍又一遍地用于相同的管道,GitLab 不会进行新的克隆,而只会在后续运行中获取更改。
如果您每次想要“克隆”策略时都想要一个新鲜的环境。有两种方法可以更改此行为:
- 通过转到项目设置 -> CI/CD -> 通用管道 -> 将“管道的 Git 策略”设置为,将项目默认值更改为“克隆”
git clone
- 通过以下方式更改策略
.gitlab-ci.yml
:
variables:
GIT_STRATEGY: clone
您可以在 GitLab 文档 - Git 策略中了解有关此设置的更多信息
推荐阅读
- django - 点赞按钮会跳转到新页面,怎么改成模态模式
- jenkins - 在詹金斯构建中的一段时间后停止 JMeter 脚本
- powershell - Where-Object、Select-Object 和 ForEach-object - 区别和用法
- php - PHP包含来自另一个多个目录的文件
- javascript - 在饼图上使用 billboardjs 显示不带小数的百分比
- android - 在这种情况下我应该使用 FLAG_ACTIVITY_CLEAR_TOP 吗?如何使用 FLAG_ACTIVITY_CLEAR_TOP 意图标志?
- sql-server - SQL Server:从 XML 数据输出中的任意节点中选择特定值 - 已回答
- java - 来自 Spring-Boot 的高级 Rest 客户端 7.1.1:java.lang.NoSuchMethodError: org.elasticsearch.action.bulk.BulkRequest.pipeline()Ljava/lang/String;
- java - 无法将争论发送到 GoogleGson 的 FromJSON 方法
- javascript - 返回内部 $http 承诺