Fastlane + Gitlab CI/CD 教學

Zhi-Hong Lin
4 min readApr 1, 2021

此篇將延續 Fastlane 入門教學 搭配 Gitlab CI 建置 CICD 流程

  1. 註冊 Gitlab runner
  2. 在 build 這個 stage 自動執行 Swiftlint 檢查
  3. 在 deploy 這個 stage 自動傳送 build 好的 ipa 到 TestFlight

安裝 GitLab CI Runner

sudo curl — output /usr/local/bin/gitlab-runner “https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64"

設定 gitlab runner 權限

sudo chmod +x /usr/local/bin/gitlab-runner

註冊 Runner

Runner 的 Executor 如何選擇?此篇 runner 的 executor 先選用 shell 來執行。

gitlab-runner register

Please enter the gitlab-ci coordinator URL

https://gitlab.com/

Please enter the gitlab-ci token for this runner

輸入 registration token

可以在下圖找到所需要的 registration token

Please enter the gitlab-ci description for this runner

輸入描述

Please enter the gitlab-ci tags for this runner (comma separated):

輸入這個 runner 的標籤

Please enter the executor: parallels, shell, virtualbox, docker+machine, docker-ssh+machine, kubernetes, custom, docker-ssh, docker, ssh:

shell

啟動 Runner

gitlab-runner start

註冊好後, Runner 的 config 會存放在 /Users/yourusername/.gitlab-runner/config.toml

設定 gitlab-ci.yml

在根目錄建立 .gitlab-ci.yml,這個 file 是要告訴 gitlab runner 要做什麼

vi .gitlab-ci.yml

首先要宣告 Pipeline 有哪些 stages,並排定他們的先後順序。

接著描述每一個 stage 裡面有哪些 job。下面以 dev 的 Pipeline 為例,為 deploy 這個 stage 設置 job

整個 dev Pipeline 如下

如何初步驗證撰寫完成的 .gitlab-ci.yml 語法是否正確?

在專案的 Pipeline 頁面右上角,有一個「CI Lint」的小工具,可以協助驗證 .gitlab-ci.yml 的語法是否正確

推送 code 到 gitlab 後,成功的話會形成如下的 CI Pipeline

在 Operations->Environments 會看到所定義的 job 會被放在 development 裡

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response