Gitlab CI/CD --- use a sample CI/CD template

0 Preface/Foreword

Pipeline, job, stage的关系如下描述: 

A pipeline is composed of independent jobs that run scripts, grouped into stages.

Stages run in sequential order, but jobs within stages run in parallel.

关键信息:

  • pipeline由独立的jobs组成,即一个pipeline至少有一个job???
  • 不同的Jobs可以组成一个stage,即一个stage至少包含一个Job???
  • 那么pipeline至少包含一个stage???
  • pipeline包含的stage,有运行顺序。如果没有显示指定顺序(可以通过指令在配置文件中指定),那么就会按照系统默认的顺序执行(buid-->test-->deploy)
  • 同一个stage中的不同Jobs,并行执行(包含多个runner情况下,没有执行顺序;否则会按照在配置文件中出现的先后顺序执行)
  • Job,是一个脚本,即命令的集合
  • 如果没有显示标记stage,那么默认为Test stage。

0.1 pipeline 

一个仓库,如果没有搭建CI/CD,那么点击sidebar 中的CI/CD选项,会出现一个导航界面。

Use a sample .gitlab-ci.yml template file to explore how CI/CD works.

Get started with GitLab CI/CD

Get familiar with GitLab CI/CD syntax by starting with a basic 3 stage CI/CD pipeline. 

0.2 Editor 

Optimize your workflow with CI/CD Pipelines

 Create a new .gitlab-ci.yml file at the root of the repository to get started.

0.3 Jobs 

 Use jobs to automate your tasks

Jobs are the building blocks of a GitLab CI/CD pipeline. Each job has a specific task, like testing code. To set up jobs in a CI/CD pipeline, add a CI/CD configuration file to your project.

0.4 Schedules 

 Scheduling Pipelines

The pipelines schedule runs pipelines in the future, repeatedly, for specific branches or tags. Those scheduled pipelines will inherit limited project access based on asscociated user.

1 方法 

1.1 Use sample template 

 

下面CI/CD的pipeline configuration file是选择main分支才会自动生成,其他的branches不会自动生成。 

  

1.1.1 CI/CD templates

点击“Browse templates ”,系统会跳转到tempates页面。

1.1.2 运行结果  

 

 

1.2 配置文件解析 

# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml

# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages

stages:          # List of stages for jobs, and their order of execution
  - build
  - test
  - deploy

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  script:
    - echo "Compiling the code..."
    - echo "Compile complete."

unit-test-job:   # This job runs in the test stage.
  stage: test    # It only starts when the job in the build stage completes successfully.
  script:
    - echo "Running unit tests... This will take about 60 seconds."
    - sleep 60
    - echo "Code coverage is 90%"

lint-test-job:   # This job also runs in the test stage.
  stage: test    # It can run at the same time as unit-test-job (in parallel).
  script:
    - echo "Linting code... This will take about 10 seconds."
    - sleep 10
    - echo "No lint issues found."

deploy-job:      # This job runs in the deploy stage.
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed."

相关推荐

最近更新

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

    2024-07-16 14:02:05       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-16 14:02:05       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-16 14:02:05       57 阅读
  4. Python语言-面向对象

    2024-07-16 14:02:05       68 阅读

热门阅读

  1. Python3 第二十二课 -- 装饰器

    2024-07-16 14:02:05       27 阅读
  2. moment()获取时间

    2024-07-16 14:02:05       20 阅读
  3. 【Vue】 style中的scoped

    2024-07-16 14:02:05       17 阅读
  4. 乡镇集装箱生活污水处理设备处理效率高

    2024-07-16 14:02:05       15 阅读
  5. 2.CATIA:与其他程序及COM库集成的方式(1/2)

    2024-07-16 14:02:05       19 阅读
  6. 微服务中的 “负载均衡策略” 简介

    2024-07-16 14:02:05       26 阅读
  7. 深入了解 Oracle 版本命名中的 i、g 及 c

    2024-07-16 14:02:05       24 阅读
  8. oracle adg切换

    2024-07-16 14:02:05       28 阅读