GitLab CI Pipeline框架

本文介紹GitLab CIPipeline框架,幫助大家理解其架構,以設計適合自己的 CI 環境。

1.基本概念

1.1 GitLab CI

GitLab CI/CD is a powerful tool built into GitLab that allows you to apply all the continuous methods (Continuous Integration, Delivery, and Deployment) to your software with no third-party application or integration needed.

GitLab CI是 GitLab 內置的功能,在你安裝好 GitLab 之後,即同時安裝了 GitLab CI。

https://docs.gitlab.com/ce/ci/introduction/

1.2 GitLab Runner

GitLab Runner is the open source project that is used to run your jobs and send the results back to GitLab. It is used in conjunction with GitLab CI, the open-source continuous integration service included with GitLab that coordinates the jobs.

GitLab Runner是任務執行器,從 GitLab CI 中獲取到任務,並按其要求完成任務的執行。https://docs.gitlab.com/runner/

1.3 Pipeline

Pipelines are the top-level component of continuous integration, delivery, and deployment.

PipeLine 即流水線是持續集成、發佈、部署的最頂層的組件。由 Stage 和 Job 組成,由.gitlab-ci.yml來定義。按觸發模式可分爲:自動觸發和人工觸發。https://docs.gitlab.com/ee/user/project/pipelines/schedules.html

1.4 .gitlab-ci.yml

GitLab CI/CD pipelines are configured using a YAML file called .gitlab-ci.yml within each project.
The .gitlab-ci.yml file defines the structure and order of the pipelines and determines: (a) What to execute using GitLab Runner. (b) What decisions to make when specific conditions are encountered. For example, when a process succeeds or fails.

.gitlab-ci.yml是 pipeline 的定義文件,即定義了流水線的實際內容。
https://docs.gitlab.com/ee/ci/yaml/README.html

1.5 Stage

Stages that define when and how to run. For example, that tests run only after code compilation.

Stage 即階段定義爲何時如何運行。

1.6 Job

Jobs that define what to run. For example, code compilation or test runs.Multiple jobs in the same stage are executed by Runners in parallel, if there are enough concurrent Runners.

Job即任務定義爲運行的內容。可自定義名稱,但 GitLab 保留了一些關鍵字。

1.7 Script

script is the only required keyword that a job needs. It’s a shell script which is executed by the Runner.

script是規劃制定具體指令。
https://docs.gitlab.com/ee/ci/yaml/README.html#script

2. Pipeline邏輯框架

2.1 層次關係圖

GitLab-CI
  |-- Pipeline P0
    |-- Stage A
        |-- Job A1
        |-- Job A2
        |-- Job ...
    |-- Stage B
        |-- Job B1
        |-- Job B2
        |-- Job ...
    |-- Stage ...
        |-- ...
  |-- Pipeline P1
    |-- Stage A
        |-- Job A1
        |-- Job A2
        |-- Job ...

2.2 部署關係圖

GitLab (GitLab-CI) Server(主)  --> GitLab (GitLab-CI) Server (熱備)
    |-- 獲取並執行 Job-- Build Server(GitLab Runner)
    |-- 獲取並執行 Job-- Test Server(GitLab Runner)

2.3 CI/CD基本工作流

2.4 Pipeline元素關係圖解


參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章