想要针对两个单独的分支从 .gitlab-ci.yml 文件运行两个单独的管道,以部署到两个单独的 aws 账户中



我为所有分支提供了针对aws "A"的所有管道。现在我想仅针对主分支运行 aws"B"账户的管道,分支管道的其余部分将触发 aws"A"账户。请指导我如何配置管道以针对同一 .gitlab-ci.yml 文件中的两个账户运行 aws"cli"命令。只想通过"aws s3"cli 命令将一些文件托管到 s3 中。

问候 阿尼凯特

在 .gitlab-ci.yml 中包含only:refsexcept:refs

job_for_master_only:
only:
refs:
- master
script:
- command_for_B_account
job_for_other_branches:
except:
refs:
- master
script:
- command_for_A_account

参考: https://docs.gitlab.com/ee/ci/yaml/#onlyrefsexceptrefs

评论后编辑

如果命令相同,只是配置不同,则可以使用作业模板。作业模板的名称需要以"."开头。使用extends关键字来利用模板:

.job_template:
script:
- some_command_that_use_environment_variable_ACCOUNT_ID
job_for_master_only:
extends:
- .job_template
only:
refs:
- master
variables:
ACCOUNT_ID: B
job_for_other_branches:
extends:
- .job_template
except:
refs:
- master
variables:
ACCOUNT_ID: A

参考: https://docs.gitlab.com/ee/ci/yaml/#extends

最新更新