建立 Pipeline 需要兩個元素
- Runner
- .gitlab-ci.yml 檔
Step 1:安裝 GitLab Runner
- 創個資料夾 C:\GitLab-Runner
- 將下載的檔案名稱改為 gitlab-runner.exe
- gitlab-runner-windows-amd64.exe → gitlab-runner.exe
- 打開 Windows PowerShell ISE
- 在 cmd.exe Keyin powershell_ise
- 在 Windows PowerShell Keyin powershell_ise or ise
- 安裝
cd C:\GitLab-Runner
.\gitlab-runner.exe install
.\gitlab-runner.exe start
安裝完後資料夾會自動產生兩個文件
- .runner_system_id
- config.toml
Step 2:註冊 Runner
Runner 有分三種
- share runner
- group runner
- project-specific runner
以下示範註冊 project-specific runner
選擇所需的 Project(Main menu → Projects )

打開 Runners 設定頁面(Settings → CI/CD → Runners[Expand])


複製註冊 command(Specific runners →Show runner installation and registration instructions)


於 PowerShell 執行 command

註冊完的資訊都可以在 config.toml 裡面看到

也可以在 GitLab 上面看到

Step 2:於專案根目錄下建立 .gitlab-ci.yml 檔案
Sample 內容
build-job:
stage: build
script:
- echo "Hello, $GITLAB_USER_LOGIN!"
test-job1:
stage: test
script:
- echo "This job tests something"
test-job2:
stage: test
script:
- echo "This job tests something, but takes more time than test-job1."
- echo "After the echo commands complete, it runs the sleep command for 20 seconds"
- echo "which simulates a test that runs 20 seconds longer than test-job1"
- sleep 20
deploy-prod:
stage: deploy
script:
- echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
environment: production
開發非常依靠 IDE 的我,使用純文字編輯器編輯 YMAL 檔實在太痛苦了。
還好 VS Code 有 Home Assistant Config Helper Extension,安裝之後用來編輯 YMAL 檔,開發時終於可以感覺到內心很平和了。

總之,以上步驟完成之後終於看到第一個 Pipeline 了!

但很哀傷的它失敗了!
但沒關係,點擊 Pipeline #166127 來看看發生什麼事情


config.toml 裡面的 pwsh 是指 PowerShell Core,而不是 Windows PowerShell。
前者沒有內建,因此要解決此問題有兩種方式
- 安裝 PowerShell Core
- 將設定改為 powershell
