gpt4 book ai didi

gitlab-ci - 使用 GitLab CI 在本地运行测试?

转载 作者:行者123 更新时间:2023-12-03 05:44:38 24 4
gpt4 key购买 nike

如果在 GitLab CI 上配置了 GitLab 项目,是否可以在本地运行构建?

我不想将我的笔记本电脑变成构建“运行器”,我只是想利用 Docker 和 .gitlab-ci.yml 在本地运行测试(即,它都是预编译的) -配置)。这样做的另一个优点是我确信我在本地和 CI 上使用相同的环境。

这里是 how to run Travis builds locally using Docker 的示例,我正在寻找与 GitLab 类似的东西。

最佳答案

从几个月前开始,使用 gitlab-runner 就可以实现这一点:

gitlab-runner exec docker my-job-name

请注意,您需要 dockergitlab-runner安装在您的计算机上以使其正常工作。

您还需要在 .gitlab-ci.yml 文件中定义 image 键。否则将无法工作。

这是我当前使用 gitlab-runner 进行本地测试的行:

gitlab-runner exec docker test --docker-volumes "/home/elboletaire/.ssh/id_rsa:/root/.ssh/id_rsa:ro"

Note: You can avoid adding a --docker-volumes with your key setting it by default in /etc/gitlab-runner/config.toml. See the official documentation for more details. Also, use gitlab-runner exec docker --help to see all docker-based runner options (like variables, volumes, networks, etc.).

由于注释困惑,我将gitlab-runner --help结果粘贴到这里,以便您可以看到gitlab-runner可以在本地进行构建:

   gitlab-runner --help
NAME:
gitlab-runner - a GitLab Runner

USAGE:
gitlab-runner [global options] command [command options] [arguments...]

VERSION:
1.1.0~beta.135.g24365ee (24365ee)

AUTHOR(S):
Kamil Trzciński <ayufan@ayufan.eu>

COMMANDS:
exec execute a build locally
[...]

GLOBAL OPTIONS:
--debug debug mode [$DEBUG]
[...]

如您所见,exec 命令是在本地执行构建

尽管there was an issue to deprecate the current gitlab-runner exec behavior ,它ended up being reconsidered具有更多功能的新版本将取代当前的 exec 功能。

Note that this process is to use your own machine to run the tests using docker containers. This is not to define custom runners. To do so, just go to your repo's CI/CD settings and read the documentation there. If you wanna ensure your runner is executed instead of one from gitlab.com, add a custom and unique tag to your runner, ensure it only runs tagged jobs and tag all the jobs you want your runner to be responsible of.

关于gitlab-ci - 使用 GitLab CI 在本地运行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32933174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com