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]

在这里插入图片描述

相关推荐

  1. gitlab高级功能CI/CD - 原理介绍(一)

    2023-12-08 05:52:04       47 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-08 05:52:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-08 05:52:04       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-08 05:52:04       82 阅读
  4. Python语言-面向对象

    2023-12-08 05:52:04       91 阅读

热门阅读

  1. 剑指 Offer(第2版)面试题 27:二叉树的镜像

    2023-12-08 05:52:04       64 阅读
  2. 如何进行多ip服务器租用?

    2023-12-08 05:52:04       54 阅读
  3. linux-tar命令、解压、压缩

    2023-12-08 05:52:04       58 阅读
  4. Linux硬链接和软连接是什么?

    2023-12-08 05:52:04       60 阅读
  5. Python 中 Thread 线程的用法

    2023-12-08 05:52:04       56 阅读
  6. [linux] 解压缩xz

    2023-12-08 05:52:04       58 阅读
  7. 中国证券交易所有哪些

    2023-12-08 05:52:04       52 阅读
  8. 贝蒂的捣蛋小游戏~(C语言)

    2023-12-08 05:52:04       51 阅读
  9. Django的模板标签相关知识累

    2023-12-08 05:52:04       55 阅读
  10. vue开发,axios网络请求框架基本用法和封装

    2023-12-08 05:52:04       48 阅读