iT邦幫忙

2025 iThome 鐵人賽

DAY 8
0

上一篇的已經初步介紹了關於 GitLab CI/CD Components 的建立以及初步如何使用。接下來將基於目前的 Hello Component 專案,我們來談談怎麼把自己的 Component 正式的發佈到 GitLab Catalog 上。

GitLab Catalog 是一個聚集 GitLab CI/CD Components 的地方,開發者可以在上面分享自己的 CI/CD Components,使用者也可以到這個平台上找到自己所需要的 Components。

目前平台除了 GitLab 官方自己提供的 Components 外,也已經有 GitLab 官方的夥伴,如 Google Cloud Platform、to-be-continuous 等團隊提供各式各樣的 Components 供使用。

在挑選的時候,可以從平台上查看 Components 上面都會標注目前釋出的版本,以及屬於它在過去 30 天的被使用次數,與 Components 打星的人數,幫數使用者做選擇的判斷。

GitLab Caralog

該如何使用 Catalog 上 Components 呢?

在這邊先以上一篇「Hello Components 2025」為例(已經預先發佈到 CI/CD Catalog,接下來會說明如何發布),在平台上,透過搜尋「Hello Component 2025」,可以找到這個元件:

search hello component 2025

點入後,可以看到關於這個 Components 更細部的說明內容,像是如何使用以及相關參數如何使用的說明。

catalog component detail

往右點 Readme 可以看到更多的元件說明

catalog component readme

從 Catalog 平台上找到心儀的 Components 之後,只要按照上面的說明就可以自己的環境使用。以 「Hello Component 2025」 專案來說,會發現,其實使用的連結跟上一篇是一樣的,不過還是有一些細微的差異,除了上一篇提到可以依據元件的 Git SHA 及Git Tags 使用外,當 Components 發佈到 Catalog 平台之後,還可以支援Partial semantic versions (部分語意版本) 及 ~latest 標註,以上一篇的案例補充後面的兩個 components 的使用如下所示(範例連結):

include:
  - component: $CI_SERVER_FQDN/mo-playground/gitlab-ci-example-2025/hello-component-2025/my-component@384cbe6028c44ae286c3d3a9e2f71276c6132510
    inputs:
      stage: build
  - component: $CI_SERVER_FQDN/mo-playground/gitlab-ci-example-2025/hello-component-2025/my-component@1.0.0
    inputs:
      stage: build
      job_name: job_from_version
  # Use Partial semantic versions
  - component: $CI_SERVER_FQDN/mo-playground/gitlab-ci-example-2025/hello-component-2025/my-component@1.0
    inputs:
      stage: build
      job_name: job_from_1.0
  # use latest
  - component: $CI_SERVER_FQDN/mo-playground/gitlab-ci-example-2025/hello-component-2025/my-component@~latest
    inputs:
      stage: build
      job_name: job_from_latest

關於 Catalog 上使用 Partial semantic versions (部分語意版本) 上的細節:

  • 使用 1.0 版本,則引入的時候,系統會協助取得 1.0.* 的最新版的 Component 。
  • 使用 1 版本,則引入的時候,會取得 1.*.* 的最新版的 Component 。
  • 使用 ~latest 則會取得目前釋出的最新版本
    假設目前已經釋出的以下版本 1.0.01.1.01.1.11.2.02.0.02.0.12.1.0,當:
  • 使用 1 會取得 1.2.0
    • 使用 1.1 會取得 1.1.1
    • 使用 ~latest 會取得 2.1.0 版本
      但如果在釋出版本時,釋出如 1.0.1-rc 這樣的 pre-release 版本時,則無法被部分語意話版本標注取得,這時候必須使用完整的版本名稱 1.0.1-rc

總結

GitLab 的 Catalog 平台,就像許多語言提供的套件平台一樣,讓開發者及使用者都有一個更方便的環境取得適用的 Components,且使用上還支援 Partial semantic versions 標註,這更讓使用者增加了很多 CI/CD 管理上的便利性。下一篇將會繼續討論,如何把 CI/CD Components 發佈到 Catalog,以及發布元件時需要注意到的一些細節。我是墨嗓(陳佑竹),期待這次的內容能帶給你實用的啟發與幫助。

參考範例

參考連結


上一篇
Day07 - 初探 GitLab CI/CD Components
下一篇
Day09 - 發布 CI/CD Components 到 GitLab Catalog
系列文
GitLab CI 2025:深入玩轉流水線與實戰紀錄11
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言