Gitlab的。如何从文件包含中为属性“选项”提供值?

Gitlab. How to provide values for property "options" from file include?

提问人:Oryctes 提问时间:11/6/2023 最后编辑:Oryctes 更新时间:11/6/2023 访问量:72

问:

在过去的两天里,我一直在为我的问题而苦苦挣扎。我尝试了几个脚本,但似乎都不起作用。我想在我的 .gitlab-ci.yaml 文件中包含来自不同位置的文件,并通过该文件动态地将值传递给“options”键。它应该看起来像这样。

variables:
DEPLOY_ENVIRONMENT:
    value: "dev"
    options: 
      - value1
      - value2
      - value3

我希望将这些值包含在我正在执行包含的文件中。 这是可以实现的吗?请提供任何提示或帮助。下面,我将分享我的 .gitlab-ci.yaml 文件的内容:

  - project: 'path/to/file'
    ref: dev
    file: '.template_api.yaml'
  - project: 'path/to/file'
    ref: dev
    file: 'deploy_config.yaml'
  - project: 'path/to/file'
    ref: dev
    file: 'options_env.yaml'
  - project: 'path/to/file'
    ref: dev
    file: 'options_branch.yaml'
    
workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
    - if: '$CI_PIPELINE_SOURCE == "pipeline"'

before_script:
  - |
    options_env=$(cat options-env.yaml | yq e '.options_env[]' -)
    options_env_string="options:\n$(echo "$options_env" | sed 's/^/  - /')"

variables:
  DEPLOY_ENVIRONMENT:
    value: "dev"
    options: 
      - ${cat options_env_list.yaml}
    description: "The deployment target. Change this variable to 'test' or 'prod' if needed."
  DEPLOY_FROM_BRANCH:
    value: "main"
    options: 
      - ${cat options_env_list.yaml}
    description: "The deployment target. Change this variable to 'test' or 'prod' if needed."

stages:
 - deploy

感谢您的帮助。

bash gitlab 包含 gitlab-ci 流水线

评论


答: 暂无答案