Gitlab中Pipeline语法
needs/include/extends
nodes 阶段并行
- 可以无序执行作业,无序按照阶段顺序运行某些作业,可以让多个阶段同时运行.
- 如果nedds:设置为指向因only/except规则而未实例化的作业,或者不存在,则创建管道时会出现yaml错误.
stages:
- build
- test
- deploy
module-a-build:
stage: build
script:
- echo "hello a"
- sleep 10
module-b-build:
stage: build
script:
- echo "hello b"
- sleep 10
module-a-test:
stage: test
script:
- echo "hello test a"
- sleep 10
needs: ["module-a-build"]
module-b-test:
stage: test
script:
- echo "hello test b"
- sleep 10
needs: ["module-b-build"]
制品下载
在使用needs,接通过artifacts:true或artifacts:false来控制工件下载,默认为true
module-a-test:
stage: test
script:
- echo "hello a test"
- sleep 10
needs:
- job: "module-a-build"
- artifacts: true
如果引入文件中和文件定义的job一样,本地文件会覆盖引入文件
include
可以引入外部yaml文件
使用合并功能可以自定义和覆盖包含本地定义CI/CD配置
include: local 引入本地配置
include:
local: 'ci/localci.yaml'
include:file 引入其它项目配置文件
include:
#项目名称
project: demo/demo/java-service
ref: master
file: '.gitlab-ci.yml'
remote
通过http/https进行引用远程文件
include:
- remote: 'https://github.com/demo-project/master/.gitlab-ci-template.yml'
extends-继承作业配置
stages:
- test
variables:
RSPEC: 'TEST'
.tests:
script:echo 'mvn test'
stage: test
only:
refs:
- tags
testjob:
extends: .tests
script: echo 'mvn clean test'
only:
variables:
- $RSPEC
合并后
variables:
RSPEC: 'TEST'
testjob:
stage: test
script: "mvn clean test"
only:
variables:
- $RSPEC
refs:
- tage