简体   繁体   English

gitlab-runner 的自定义 CI 目录

[英]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 will find your settings gitlab-ci 会找到你的设置
  • technically the the gitlab-ci.yml and the .git directory are in the same directory, so gitlab-runner should be fine.从技术上讲, gitlab-ci.yml.git目录位于同一目录中,因此gitlab-runner应该没问题。
  • all of your real ci-config is still in one directory你所有真正的 ci-config 仍然在一个目录中

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM