GitLab CI/CD 语法六

102 阅读1分钟

needs 阶段并行

  • 可无序执行作业,无序按照阶段顺序运行某些作业,可以让多个阶段同时运行。
  • 如果needs: 设置为指向因only/except规则而未实例化的作业,或者不存在,则创建管道会出现YAML错误。
stages:
  - build
  - test

module-a-build:
  stage: build
  script:
    - echo "hello 3a build"
    - sleep 10

module-b-build:
  stage: build
  script:
    - echo "hello 3b build"
    - sleep 10

module-a-test:
  stage: test
  script:
    - echo "hello 3a test"
    - sleep 10
  needs:
    - module-a-build

module-b-test:
  stage: test
  script:
    - echo "hello 3b test"
    - sleep 10
  needs:
    - module-b-build

include: local 引入本地配置

  • 可以允许引入外部YAML文件,文件具有扩展名.yml或.yaml
  • 使用合并功能可以自定义和覆盖包含本地定义的CI/CD配置
  • 引入同一存储库中的文件,使用相对于根目录的完整路径进行引用,与配置文件在同一分支上使用。
include:
  local: 'ci/localci.yml'

include: file 引入其他项目配置

# 引入demo/demo-java-service项目master分支的.gitlab-ci.yml

include:
  - project: demo/demo-java-service
    ref: master
    file: '.gitlab-ci.yml'

include: template 引入官方配置

include:
  - template: Auto-DevOps.gitlab-ci.yml

include:remote 引入远程配置

用于通过HTTP/HTTPS包含来自其他位置的文件,并使用完整URL进行引用,远程文件必须可以通过简单的GET请求公开访问,因为不支持远程url中的身份验证架构

include:
  - remote: 'https://gitlab.com/awesome-project/raw/master/.gitlab-ci-template.yml'

extends 继承作业配置

.test:
  script: mvn test
  stage: test
  only: 
   refs:
     - tags
     
testjob:
  extends: .test
  script: mvn clean test
  only:
    variables:
      - $RSPEC