gitlab-ci/cd(七)流水线类型

1、常规类型

例如之前的几章的流水线,都是常规类型

2、DAG流水线,job的依赖关系(needs)

stages:
    - stage-1
    - stage-2

job-1:
    stage: stage-1
    needs: []
    script: 
      - echo "job-1 started"
      - sleep 5
      - echo "job-1 done"

job-2:
    stage: stage-1
    needs: []
    script: 
      - echo "job-2 started"
      - sleep 60
      - echo "job-2 done"

job-3:
    stage: stage-2
    needs: [job-1]
    script: 
      - echo "job-3 started"
      - sleep 5
      - echo "job-3 done"

job-4:
    stage: stage-2
    needs: [job-2]
    script: 
      - echo "job-4 started"
      - sleep 5
      - echo "job-4 done"
GitOps、新兴技术能力gitlab-ci/cd(七)流水线类型插图

3、父子流水线(include)

https://blog.51cto.com/devopsvip/2511546

4、多项目流水想

主流水线code

stages:
  - ready
  - build
  - create

default:
  tags:
    - shell  

ready_job:
  stage: ready
  script:
    - echo '基座准备工作'
  only:
    - master

build_self_job:
  stage: build
  script:
    - echo '开始构建多个应用,生成制品'
    - ls -l
    - cp -rf public/. /home/gitlab-runner/cicd-group/base
    - cd /home/gitlab-runner/cicd-group/base
    - ls -l 
  artifacts:
    paths:
    - public
  only:
    - master

build_other_job:
  stage: build
  trigger: 
    project: c860/sub-app
    branch: master
    strategy: depend
    
creat_app:
  stage: create
  script:
    - cd /home/gitlab-runner/cicd-group/sub-app
    - ls -l

子项目流水线code

default:
  tags:
    - shell    
build_job:
  stage: deploy
  script:
    - echo '开始构建子应用'
    - ls -l
    - cp -rf public/. /home/gitlab-runner/cicd-group/sub-app
    - cd /home/gitlab-runner/cicd-group/sub-app
    - ls -l     
  artifacts:
    paths:
      - public
  only:
    - master

5、合并请求流水线

合并请求流水线,即当代码合并的时候执行

only:
  - merge_requests