GitLab 與 CICD

Add the official GitLab repository:

新增官方 GitLab 倉庫:

安裝 GitLab Runner

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash

安裝最新版本的 GitLab Runner,或跳到下一步安裝特定版本:

sudo apt install gitlab-runner

開啟gitlab > Settings > CI/CD > Runners > New project runner

填寫資料

按下建立專案後

按造步驟註冊本機端的gitlab-runner

gitlab-runner register  --url <https://gitlab.com>  --token glrt-t3_******************
gitlab-runner run

使用背景執行:

nohup gitlab-runner run &> gitlab-runner.log &

測試是否成功:

開啟gitlab > Build > Pipeline editor

撰寫測試腳本:

test-ssh-on-gcp:
    tags:
        - filament-CICD
    script:
        - echo "安裝成功"

按下 Commit changes

等待執行

查看Jobs Status 是否為Passed 為Failed,可查看此任務為何失敗,在針對失敗做排除

例:

hint: You can replace "git config" with "git config --global" to set a defaulthint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
Cleaning up project directory and file based variables
ERROR: Job failed: exit status 1
工作技能 GitLab CI/CD 學習紀錄