如何使用 gitlab ci/cd 在项目之间共享相同的配置文件
我有一些对于许多项目来说都是相同的通用配置文件。管理起来非常痛苦,因为它们只是重复的,当我对一个文件进行修改时,我需要对所有文件进行修改。
我想找到一个使用gitlab ci/cd 来跨不同项目共享通用配置文件的解决方案。
我在 Gitlab 文档中看到,您可以在此处包含其他 gitlab 文件 / cd 此处< /a>.但我不想只共享 yaml 配置文件,我想共享我的项目中所有相同的配置文件。
我发现了一个想法,但我不知道它是否好。
想象一个名为“A”的项目和一个名为“Common Configurations Files”的项目。
“Common Configurations Files”项目将包含“config”文件夹中的所有常见配置文件和一个 gitlab ci/cd 文件,该文件具有可以将文件复制到根文件夹的功能。
项目 A 将 包含 文件,并调用 before_script 步骤来复制文件到根文件夹。
我不知道它是否可以工作,我也不知道该怎么做。
我看到另外两个选项,但我不知道它是否合适:
I have some common configurations files that are the same for many projets. It's very painful to manage because they are just duplicate and when I have a modification for one file I need to do it for all of them.
I want to find a solution with gitlab ci/cd to share common configuration files across different projects.
I saw in the Gitlab documentation that you can include other gitlab files here / cd here. But I don't want to share only the yaml configuration file, I want to share all the configuration files that are the same in my projects.
I found an idea but I don't know if it's a good one.
Imagine a project named "A" and a project named "Common Configurations Files".
The "Common Configurations Files" project will contain all the common configurations files in a "config" folder and a gitlab ci/cd file with a function that can copy the files to the root folder.
Project A will include files and will call the before_script step to copy the files to the root folder.
I don't know if it can work and I don't know how to do it.
I saw two other options but I don't know if it's suitable:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这两个选项,无论是使用子模块还是工件,都应该适合您的情况。使用子模块会增加一点复杂性,因为您需要在所有依赖存储库中更新子模块。
适合这里的另一个选项是使用 Gitlab 通用包 。如果您有一个包含所有配置文件的存储库,我建议为此存储库创建一个管道,在更改时对存储库进行版本/标记。版本控制后,我将压缩内容并将其推送到该项目包存储库。
在所有依赖项目中,在 before_script 中,您只需下载并解压 zip 文件即可。
文档中的示例如下所示,可能会帮助您入门。
Both options, either working with a submodule or artifacts, should work for your case. Using submodules would add a little bit more complexity as you would need to keep the submodules updated in all your dependent repositories.
Another option that would be suitable here would be the use of Gitlab Generic Packages. If you have a Repository that includes all your configuration files, I would suggest creating a pipeline for this repository which versions/tags the repo upon changes. After versioning, I would zip the content up and push it to this projects package repository.
In all your dependent projects, in the before_script you could just download and extract the zip file.
The example in the docs looks like this and might help you get started.