避免 Gitlab 中的路径冗余 CI include
Avoid path redundancy in Gitlab CI include
为了改进我的 Gitlab CI 文件的结构,我包含了一些特定的文件,例如
include:
- '/ci/config/linux.yml'
- '/ci/config/windows.yml'
# ... more includes
为了避免路径容易出错的冗余我想把它放到一个变量中,比如:
variables:
CI_CONFIG_DIR: '/ci/config'
include:
- '${CI_CONFIG_DIR}/linux.yml' # ERROR: "Local file `${CI_CONFIG_DIR}/linux.yml` does not exist!"
- '${CI_CONFIG_DIR}/windows.yml'
# ... more includes
但是这行不通。 Gitlab CI 声称 ${CI_CONFIG_DIR}/linux.yml
不存在,尽管文档说允许包含路径中的变量,请参阅 https://docs.gitlab.com/ee/ci/variables/where_variables_can_be_used.html#gitlab-ciyml-file.
也没有用的是包含一个文件 /ci/config/main.yml
并从中包含没有路径的特定配置:
# /ci/config/main.yml
include:
- 'linux.yml' # ERROR: "Local file `linux.yml` does not exist!"
- 'windows.yml'
# ... more includes
我怎样才能完成这项工作,或者是否有一种替代方法可以只在一个地方定义路径而不会使它变得太复杂?
这个暂时好像没有实现,暂时有一个open issue在积压中。
此外,根据文档说明您可以在 include
部分中使用 variables
,这些仅适用于预定义变量。
看看 GitLab 14.2(2021 年 8 月)是否可以提供帮助:
Use CI/CD variables in include statements in .gitlab-ci.yml
You can now use variables as part of include
statements in .gitlab-ci.yml
files.
These variables can be instance, group, or project CI/CD variables.
This improvement provides you with more flexibility to define pipelines.
You can copy the same .gitlab-ci.yml
file to multiple projects and use variables to alter its behavior.
This allows for less duplication in the .gitlab-ci.yml
file and reduces the need for complicated per-project configuration.
See Documentation and Issue.
为了改进我的 Gitlab CI 文件的结构,我包含了一些特定的文件,例如
include:
- '/ci/config/linux.yml'
- '/ci/config/windows.yml'
# ... more includes
为了避免路径容易出错的冗余我想把它放到一个变量中,比如:
variables:
CI_CONFIG_DIR: '/ci/config'
include:
- '${CI_CONFIG_DIR}/linux.yml' # ERROR: "Local file `${CI_CONFIG_DIR}/linux.yml` does not exist!"
- '${CI_CONFIG_DIR}/windows.yml'
# ... more includes
但是这行不通。 Gitlab CI 声称 ${CI_CONFIG_DIR}/linux.yml
不存在,尽管文档说允许包含路径中的变量,请参阅 https://docs.gitlab.com/ee/ci/variables/where_variables_can_be_used.html#gitlab-ciyml-file.
也没有用的是包含一个文件 /ci/config/main.yml
并从中包含没有路径的特定配置:
# /ci/config/main.yml
include:
- 'linux.yml' # ERROR: "Local file `linux.yml` does not exist!"
- 'windows.yml'
# ... more includes
我怎样才能完成这项工作,或者是否有一种替代方法可以只在一个地方定义路径而不会使它变得太复杂?
这个暂时好像没有实现,暂时有一个open issue在积压中。
此外,根据文档说明您可以在 include
部分中使用 variables
,这些仅适用于预定义变量。
看看 GitLab 14.2(2021 年 8 月)是否可以提供帮助:
Use CI/CD variables in include statements in .gitlab-ci.yml
You can now use variables as part of
include
statements in.gitlab-ci.yml
files.
These variables can be instance, group, or project CI/CD variables.This improvement provides you with more flexibility to define pipelines.
You can copy the same.gitlab-ci.yml
file to multiple projects and use variables to alter its behavior.
This allows for less duplication in the.gitlab-ci.yml
file and reduces the need for complicated per-project configuration.
See Documentation and Issue.