6、pipline 类型及触发方式

流水线类型参考文档: https://docs.gitlab.cn/jh/ci/pipelines/pipeline_architectures.html

1、流水线类型:

1、基本流水线(按照job个阶段执行)

yaml 复制代码
stages:
	- install
	- lint-code
	- build
	- deploy

job_install:
  stage: install
  tags: 
    - test
  script:
    - npm install
    
job_lint_code:
  stage: lint-code
  tags: 
    - test
  script:
    - npm run eslint
  allow_failure: true

2、DAG流水线(有向无环图流水线)

  • 关键词 needs

如果效率对您很重要,并且您希望一切都尽可能快地运行,则可以使用有向无环图(DAG)。 使用 needs关键字 定义作业之间的依赖关系。当系统知道您的作业之间的关系时,它可以尽可能快地运行所有内容,甚至在可能的情况下跳到后续阶段。

在下面的示例中,如果 build_a 和 test_a 比 build_b 和 test_b 快得多,即使 build_b 仍在运行,系统也会启动 deploy_a。

yaml 复制代码
stages:
  - build
  - test
  - deploy

image: alpine

build_a:
  stage: build
  script:
    - echo "This job builds something quickly."

build_b:
  stage: build
  script:
    - echo "This job builds something else slowly."

test_a:
  stage: test
  needs: [build_a]
  script:
    - echo "This test job will start as soon as build_a finishes."
    - echo "It will not wait for build_b, or other jobs in the build stage, to finish."

test_b:
  stage: test
  needs: [build_b]
  script:
    - echo "This test job will start as soon as build_b finishes."
    - echo "It will not wait for other jobs in the build stage to finish."

deploy_a:
  stage: deploy
  needs: [test_a]
  script:
    - echo "Since build_a and test_a run quickly, this deploy job can run much earlier."
    - echo "It does not need to wait for build_b or test_b."

deploy_b:
  stage: deploy
  needs: [test_b]
  script:
    - echo "Since build_b and test_b run slowly, this deploy job will run much later."

3、父子流水线

  • 关键词 trigger: include

使用场景 : 项目和使用文档是分离的,在部署项目的同时,也要更新使用文档

yaml 复制代码
stages:
  - triggers

trigger_a:
  stage: triggers
  trigger:
    include: a/.gitlab-ci.yml
  rules:     # 就是修改变动a下面的文件,就会触发这个 a下面的这个.yml, 不会执行trigger_b
    - changes:
        - a/*

trigger_b:
  stage: triggers
  trigger:
    include: b/.gitlab-ci.yml
  rules:
    - changes:
        - b/*

4、多项目流水线

  • 使用场景: 比如微前端,需要同时部署几个子应用
yaml 复制代码
trigger:
	stage: deploy
	trigger:
		project: root/minapp  #指向的其他应用项目
		branch: master
		stragegy: depend   #子流水线的状态会在父流水线显示出来

5、合并请求流水线

yaml 复制代码
build_a:
  stage: build
  script:
    - echo "This job builds something quickly."
	only:
		- merge_requests

2、流水线的触发

1、推送代码

2、定时触发

注释: 自定义时间: 21: 分钟 17:小时 15: 天数 10: 月份 *:每月

3、url 触发

场景:(使用机器人 or 发布平台)

  • curl
bash 复制代码
curl -X POST \
--fail \
-F token=TOKEN \
-F ref=REF_NAME \
http://gitlab.21silva.top:8090/api/v4/projects/3/trigger/pipeline
  • webhook (群机器人)
bash 复制代码
http://gitlab.21silva.top:8090/api/v4/projects/3/ref/REF_NAME/trigger/pipeline?token=TOKEN

4、手动

yaml 复制代码
job_deploy_main:
	stage: deploy
	image: docker
	tags: 
	- test
	script:
	- docker build -t testimageprod .
	- if [ $(docker ps -aq --filter name=mycicd-containerprod) ]; then docker rm -f mycicd-containerprod;fi
	- docker run -d -p 8082:80 --name mycicd-containerprod testimageprod
	environment:
		name: silvaProd
		url: 访问url
	only:
	- main
	when: manual
相关推荐
东风西巷几秒前
Atlantis Word Processor:全方位的文字处理专家
前端·学习·word·软件需求
今天不要写bug13 分钟前
基于elementUI实现一个可编辑的表格(简洁版)
前端·javascript·elementui
上优15 分钟前
Vue3纯前端同源跨窗口通信移动AGV小车
前端·vue.js·状态模式
h_k1008616 分钟前
Chrome 插件开发入门技术文章大纲
前端·chrome
一只小阿乐16 分钟前
vue-router 的实现原理
前端·javascript·vue.js·路由·vue-router
Zz_waiting.17 分钟前
案例开发 - 日程管理 - 第七期
开发语言·前端·javascript·vue.js·html·路由
一只小风华~21 分钟前
Vue:事件处理机制详解
前端·javascript·vue.js·typescript·前端框架
dy17174 小时前
element-plus表格默认展开有子的数据
前端·javascript·vue.js
2501_915918418 小时前
Web 前端可视化开发工具对比 低代码平台、可视化搭建工具、前端可视化编辑器与在线可视化开发环境的实战分析
前端·低代码·ios·小程序·uni-app·编辑器·iphone
程序员的世界你不懂8 小时前
【Flask】测试平台开发,新增说明书编写和展示功能 第二十三篇
java·前端·数据库