在上一篇的已經初步介紹了關於 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 打星的人數,幫數使用者做選擇的判斷。
在這邊先以上一篇「Hello Components 2025」為例(已經預先發佈到 CI/CD Catalog,接下來會說明如何發布),在平台上,透過搜尋「Hello Component 2025」,可以找到這個元件:
點入後,可以看到關於這個 Components 更細部的說明內容,像是如何使用以及相關參數如何使用的說明。
往右點 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
1.0
版本,則引入的時候,系統會協助取得 1.0.*
的最新版的 Component 。1
版本,則引入的時候,會取得 1.*.*
的最新版的 Component 。~latest
則會取得目前釋出的最新版本1.0.0
、1.1.0
、1.1.1
、1.2.0
、2.0.0
、2.0.1
、2.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,以及發布元件時需要注意到的一些細節。我是墨嗓(陳佑竹),期待這次的內容能帶給你實用的啟發與幫助。