语法1:cache
explain*(待后续有需要再补充)
把目录缓存,让上一个job的缓存带到下一个job里面使用。实际生产据说用的比较少。有需要再学习
语法2:artifacts(待后续有需要再补充)
explain
把作业产生的一些文件之类的输出,给到gitlab的UI界面上面提供下载。
语法3:dependencies(待后续有需要再补充)
explain
指定使用前面作业产生的制品
exmaple
job2:
dependencies:
- job1
语法4:needs
explain
- 可无序执行作业,无需按照阶段顺序运行某些作业,可以让多个阶段同时运行。
- 如果needs:设置为指向因only/except规则而未实例化的作业,或者不存在,则创建管道时会出现YAML错误。
exmaple
stages:
- build
- test
- deploy
module-a-build:
stage: build
script:
- echo "hello3a"
- sleep 10
module-b-build:
stage: build
script:
- echo "hello3b"
- sleep 20
module-a-test:
stage: test
script:
- echo "hello3a"
- sleep 5
needs:
- "module-a-build"
module-b-test:
stage: test
script:
- echo "hello3b"
- sleep 10
needs:
- "module-b-build"
同时进行
语法5:include
可以允许引入外部YAML文件,文件具有扩展名.yml或.yaml
使用合并功能可以自定义和覆盖包含本地定义的CI/CD配置。
引入同一存储库中的文件,使用相对于根目录的完整路径进行引用,与配置文件在同一分支上使用。
gitlab-ci.yml
stages:
- build
- test
- deploy
include:
local: 'ci/localci.yml'
# 引用其他项目的配置文件()
# project: demo/demo-java-service
# branch: master
# file: .gitlab-ci.yml
# 引入远程的配置
# - remote: 'https://gitlab.com/.gitlab-ci-template.yml'
等等
ci/localci.yml
deployjob:
stage: deploy
script:
- echo 'deploy'
语法6:extends
explain
以模板为基础,进行覆盖
example
stages:
- test
variables:
RSPEC: 'test'
.tests:
script: echo "mvn test"
stage: test
only:
refs:
- branches
testjob:
extends: .tests
script: echo "mvn clean test"
only:
variables:
- $RSPEC