[英]Custom CI Directory for gitlab-runner
I have a project on gitlab that uses a custom CI/CD directory like so:我在 gitlab 上有一个项目,它使用自定义 CI/CD 目录,如下所示:
my-project/
├─ .ci/
│ ├─ gitlab-ci.yml
│ ├─ local-ci.sh
├─ .git/
├─ my-project/
├─ tests/
Where local-ci.sh is a script that invokes gitlab-runner
on the pipeline in gitlab-ci.yml
.其中 local-ci.sh 是在gitlab-ci.yml
中的管道上调用gitlab-runner
的脚本。
On gitlab you can identify a custom path for the gitlab-ci.yml file, so the pipeline works when I push to the remote repository.在 gitlab 上,您可以确定 gitlab-ci.yml 文件的自定义路径,因此当我推送到远程存储库时管道可以正常工作。 I'd like to run the same CI pipeline on my local machine using gitlab-runner
and Docker before pushing to the remote repository.在推送到远程存储库之前,我想使用gitlab-runner
和 Docker 在我的本地计算机上运行相同的 CI 管道。
The issue I'm running into is when I run the pieline locally, gitlab-runner
expects the .git
directory to be in the same directory as the gitlab-ci.yml
script.我遇到的问题是当我在本地运行 pieline 时, gitlab-runner
期望.git
目录与gitlab-ci.yml
脚本位于同一目录中。 Is there a way to configure where the git
directory is when running gitlab-runner
?有没有办法在运行gitlab-runner
时配置git
目录的位置?
Specifically, from this command (Linting is a stage of the pipeline):具体来说,从这个命令(Linting 是管道的一个阶段):
gitlab-runner exec docker Linting
I get this error:我收到此错误:
fatal: '<absolute path>/my-project/.ci' does not appear to be a git repository
fatal: Could not read from remote repository.
When I copy the gitlab-ci.yml
script into the root directory, and change the working directory in the local-ci.sh
script, the pipeline finishes without issue.当我将gitlab-ci.yml
脚本复制到根目录,并更改local-ci.sh
脚本中的工作目录时,管道顺利完成。 Any thoughts?有什么想法吗?
EDIT: adding notes about the errors and copying the CI script.编辑:添加关于错误的注释并复制 CI 脚本。
I think the easiest solution would be to add a file my-project/gitlab-ci.yml
which just includes the real gitlab-ci.yml
.我认为最简单的解决方案是添加一个文件my-project/gitlab-ci.yml
,它只包含真正的gitlab-ci.yml
。
include:
- local: .ci/gitlab-ci.yml
This should solve your problem, because这应该可以解决您的问题,因为
gitlab-ci.yml
and the .git
directory are in the same directory, so gitlab-runner
should be fine.从技术上讲, gitlab-ci.yml
和.git
目录位于同一目录中,因此gitlab-runner
应该没问题。You might even get away with using an symbolic link instead:您甚至可以使用符号链接来代替:
ln -s .ci/gitlab-ci.yml gitlab-ci.yml
This would arguably be even cleaner (because there is no code added to your reposity, just a link).可以说这会更干净(因为没有代码添加到您的存储库中,只有一个链接)。 You'd have to try if all of your tools can work with symbolic links (I suspect they can).如果您的所有工具都可以使用符号链接(我怀疑它们可以),您将不得不尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.