gitlab高级功能之CI/CD组件 - 实践(二)

上一篇主要讲解了CI/CD组件的原理,看起来稍微有一点枯燥,那么接下来给大家演示下如何使用。

案例

  • 创建一个项目(README.md,template目录)

案例1

step1: 在template中新建yml文件,cat templates/test-stage.yml

说明:

1、创建变量变量stage,stage-2,stage-3,分别默认值为test,build,deploy

2、编写三个job

复制代码
spec:
  inputs:
    stage:
      default: test
    stage-2:
      default: build
    stage-3:
      default: deploy
---
component-job-1:
  script: 
    - echo job 1
    - env
  stage: $[[ inputs.stage ]]

component-job-2:
  script: 
    - echo job 2
    - env
  stage: $[[ inputs.stage-2 ]]

component-job-3:
  script: 
    - echo job 3
    - env
  stage: $[[ inputs.stage-3 ]]
step2: 编写.gitlab-ci.yml文件

方式1: 三个变量使用默认值,表示引用里面的三个job

复制代码
include:
  - component: 192.168.31.100/ops/components/test-stage@main
# 因为使用的是默认的值,也可以忽略下一行的stages写法
stages: [build,deploy,post]

方式2: 三个变量使用定义不同的值,依然饮用里面的三个job

复制代码
include:
  - component: 192.168.31.100/ops/components/test-stage@main
    inputs:
      stage: part1
      stage-2: part2
      stage-3: part3

stages: 
  - part1
  - part2
  - part3

方式3: 只使用某个变量,即只引用某一个job。目前并支持这种行为,除非编写某个功能的job

案例2

step1: 在template中新建yml文件,cat templates/test-v1.yml
复制代码
spec:
  inputs:
    name: 
      default: wangkaixuan
    department:
      default: cs
    what: 
      default: support
    stage:
      default: pre
---
doing-what:
  stage: $[[ inputs.stage ]]
  script: 
    - your name is $[[ inputs.name ]],you are located in $[[ inputs.department ]],your daily work are doing $[[ inputs.what ]].
    - env
step2: 编写.gitlab-ci.yml文件
复制代码
include:
  - component: 192.168.31.100/ops/components/test-stage@main
    inputs:
      stage: one
      stage-2: two
      stage-3: three
  - component: 192.168.31.100/ops/components/test-v1@main
    inputs:
      name: wkx
      what: "all do work"
      stage: post

stages: [one,two,three,post]
相关推荐
网安蟹佬霸19 小时前
Zero Trust零信任架构实战:从架构设计到落地部署
安全·网络安全·ci/cd·架构·自动化·网安
极小狐1 天前
极狐GitLab Runner 自托管安全加固指南
安全·ci/cd·gitlab·devops·runner·安全加固
晓晓_za8986682 天前
Geo 优化服务 CI/CD 流水线搭建:源码自动构建、测试与灰度发布
运维·服务器·tcp/ip·spring·缓存·ci/cd
潘正翔2 天前
jenkins构建cicd流水线
运维·服务器·ci/cd·容器·自动化·jenkins·cicd
终末圆2 天前
GitHub Actions 实现 CI/CD
运维·ci/cd·github·运维开发·devops
钝挫力PROGRAMER2 天前
Windows Docker 环境搭建 GitLab CI/CD 流水线
windows·docker·gitlab·gitlab-runner
晓晓_za8986682 天前
Geo 优化源码蒸馏词机制:地域词库构建与匹配逻辑详解
运维·tcp/ip·spring·缓存·ci/cd
DsirNg4 天前
别把联调当验收:用可执行契约管住接口变更
ci/cd·mock·openapi·契约测试·接口契约·前后端协作·pact
进哥AI研习社5 天前
AtomCode 高阶玩法揭秘:Headless 模式集成 CI/CD、Skills 自定义与项目指令文件深度实战
ci/cd·atomcode·headless 模式·daemon 服务·skill 自定义·.atomcode.md·自动化审查
运维开发那些事5 天前
GitOps最佳实践 (gitlab ci + ArgoCD)
ci/cd·devops