(共566篇)
全部分类

CI/CD中的include--引入其他配置文件
[ CICD ] 

ci/cd 配置文件支持通过 include 引入其他的 yaml 文件, 且支持同时引入多个文件

引入项目内的单个文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# variables.yaml
variables:
  BUILD_MODE: "dev"

job2:
  stage: test
  tags:
    - nuxt2
  script:
    - echo 'test'

# .ci.yaml
include: variables.yaml
job1:
  stage: build
  tags:
    - nuxt2
  script:
    - echo $BUILD_MODE

在这个案例中, job1 执行的时候会输出’dev’, job2 也会在 job1 执行结束后正常执行并输出"test"

其中.ci.yaml 中也可以写成这样:

1
2
3
4
5
6
include:
  - variables.yaml

# 或者
include:
  - local: variables.yaml

引入网络上的指定 yaml 文件

1
2
3
4
5
6
7
8
9
include: "https://gitlab.com/awesome-project/raw/main/.before-script-template.yml"

# 或者
include:
  - "https://gitlab.com/awesome-project/raw/main/.before-script-template.yml"

# 或者
include:
  - remote: "https://gitlab.com/awesome-project/raw/main/.before-script-template.yml"

引入同一个仓库内其他项目的 yaml 文件

需要指定 yaml 所在的项目组名/项目名称/分支名称/文件名称

1
2
3
4
include:
  - project: project-group/project-name
    ref: main
    file: file-path.yaml