在单独的YML文件中包含GitLab Runner标签列表
我们正在为DevOps,配置管理等广泛使用GitLab CI/CD管道。有一长串的GitLab跑步者列表,现在在每个项目中都在gitlab-ci.yml中定义了一长串。通过使用“标签”和“仅”,我们就定义了何时在不同的跑步者上运行作业。问题是如何将Runner列表放入单独的文件中,然后将其包含在必需的地方?现在,这也许是可能的,因为Gitlab在去年的发展很快。首先,我们从扩展关键字开始:
gitlab-ci.yml
.devphase:
stage: build
when: manual
only:
- dev
...
Updating development environment (runner1):
extends: .devphase
tags:
- runner1
Updating development environment (runner2):
extends: .devphase
tags:
- runner2
...
这使gitlab-ci.yml更易于阅读,因为我们可以在配置文件的末尾分别列出跑步者。但是,为每个跑步者定义所有这些参数并不是很高效或优雅。后来的GitLab引入了关键字“并行”和“矩阵”。现在我们可以做到这一点:
gitlab-ci.yml
.devphase:
stage: build
only:
- dev
tags:
- ${DEV_RUNNER}
...
Updating development environment:
extends: .devphase
parallel:
matrix:
- DEV_RUNNER: runner1
- DEV_RUNNER: runner2
...
只有一个扩展了部分,然后列出了跑步者列表,这已经很不错了。下一个自然的后续问题是如何将此列表放入单独的配置文件中,以便在不触摸主gitlab-ci.yml的情况下轻松地复制和维护它?我不确定如何以及在何处包含关键字,甚至可能。例如,这不起作用(管道无法启动)。
gitlab-ci.yml:
.devphase:
stage: build
parallel:
matrix:
include: gitlab-ci-dev-runners.yml
only:
- dev
tags:
- ${DEV_RUNNER}
...
gitlab-ci-dev-runners.yml
- DEV_RUNNER: runner1
- DEV_RUNNER: runner2
...
gitlab解释是否包含一些“不兼容”秩序中的变量?这里有其他编码人员在这里遇到了同样的问题吗?
We are using extensively Gitlab CI/CD pipelines for DevOps, configuration management etc. There is a long list of Gitlab runners which is now defined in gitlab-ci.yml in every project. By using "tags" and "only" we then define when to run jobs on different runners. The question is how to put the runner lists in separate files and then include them in required places? This is maybe now possible as Gitlab has evolved fast during last years. First we started with extends keyword:
gitlab-ci.yml
.devphase:
stage: build
when: manual
only:
- dev
...
Updating development environment (runner1):
extends: .devphase
tags:
- runner1
Updating development environment (runner2):
extends: .devphase
tags:
- runner2
...
This made the gitlab-ci.yml easier to read as we could list the runners separately at the end of the configuration file. However defining all these parameters for every runner is not very efficient or elegant. Somewhat later Gitlab introduced keywords "parallel" and "matrix". Now we can do this:
gitlab-ci.yml
.devphase:
stage: build
only:
- dev
tags:
- ${DEV_RUNNER}
...
Updating development environment:
extends: .devphase
parallel:
matrix:
- DEV_RUNNER: runner1
- DEV_RUNNER: runner2
...
Only one extends section and then list of runners which is pretty nice already. The next natural follow-up question is how one could put this list to a separate configuration file so that it would be easily copied and maintained without touching the main gitlab-ci.yml? I'm not sure how and where to use include keyword or is it even possible. For example this don't work (pipeline doesn't start).
gitlab-ci.yml:
.devphase:
stage: build
parallel:
matrix:
include: gitlab-ci-dev-runners.yml
only:
- dev
tags:
- ${DEV_RUNNER}
...
gitlab-ci-dev-runners.yml
- DEV_RUNNER: runner1
- DEV_RUNNER: runner2
...
Is Gitlab interpreting includes and variables in some "uncompatible" order orso? Is there any fellow coders who have faced this same problem here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论