needs/include/extends
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一样,本地文件会覆盖引入文件
可以引入外部yaml文件
使用合并功能可以自定义和覆盖包含本地定义CI/CD配置
include:
local: 'ci/localci.yaml'
include:
#项目名称
project: demo/demo/java-service
ref: master
file: '.gitlab-ci.yml'
通过http/https进行引用远程文件
include:
- remote: 'https://github.com/demo-project/master/.gitlab-ci-template.yml'
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