【发布时间】:2023-01-23 14:44:31
【问题描述】:
我们有一个构建软件包的 GitLab CI/CD .gitlab-ci.yaml 文件。 .gitlab-ci.yaml 有一个变量,用于确定应该为哪个操作系统版本构建包。我们想在其他 GitLab 项目中使用 include 关键字来包含这个 .gitlab-ci.yaml 以允许我们构建包。我们想为多个操作系统版本构建这个包。但是,我们不能,因为 GitLab 不允许我们 include 同一个文件两次。还有另一种方法吗?
为了更具体地了解这一点,假设我们要包含在其他项目中的 .gitlab-ci.yaml 文件是这样的:
# common/gitlab-templates/.gitlab-ci.yaml
variables:
OS_RELEASE: 10.0
build-package:
script: echo "building for $OS_RELEASE"
在另一个 GitLab 项目中,我们想做这样的事情:
# Build for version 8.0
include:
- project: 'common/gitlab-templates'
file: '.gitlab-ci.yml'
variables:
OS_RELEASE: 8.0
# Build for version 9.0
include:
- project: 'common/gitlab-templates'
file: '.gitlab-ci.yml'
variables:
OS_RELEASE: 9.0
# Build for version 10.0
include:
- project: 'common/gitlab-templates'
file: '.gitlab-ci.yml'
variables:
OS_RELEASE: 10.0
但是,以上是无效的 .gitlab-ci.yaml 语法。
我们如何解决这个问题?
【问题讨论】:
-
请注意,如果这确实有效,您将获得三个全部名为 build-package 的作业:这些作业将相互覆盖,而不是按预期执行。
标签: gitlab-ci