Gitlab CI/CDとGitlab Runnerの初期調査
参考にしたURL
クラスメソッドさんの記事は助かったが、流石に古かったのでそのままという訳にはいかなかった
諸元
Gitlabサーバ
オンプレのVM
ubuntu22
Gitlab ver 16.7.0
Gitlab Runnerを導入するサーバ
オンプレのVM
Ubuntu24
とりあえずDockerは利用しない
GitlabとGitlab Runnerのバージョンについて
GitlabとGitlab Runnerのバージョンは可能な限り合わせた方が良いとの事
公式のGitlab Runnerインストール手順
Gitlab Runnerのインストール
レポジトリの追加
$ curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
特定バージョンのRunnerのインストール
$ apt-cache madison gitlab-runner
$ sudo apt-get install gitlab-runner=16.7.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package gitlab-runner is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
gitlab-runner-helper-images
E: Version '16.7.0' for 'gitlab-runner' was not found
そんなバージョンは無いとの事。
現状の最低のバージョンでインストールする
$ sudo apt-get install gitlab-runner=16.9.2-1
...
Do you want to continue? [Y/n] Yで続行する
動作確認
$ sudo systemctl status gitlab-runner
$ sudo systemctl status gitlab-runner
● gitlab-runner.service - GitLab Runner
Loaded: loaded (/etc/systemd/system/gitlab-runner.service; enabled; preset: enabled)
Active: active (running) since Wed 2025-04-09 15:59:27 JST; 32s ago
Main PID: 9540 (gitlab-runner)
Tasks: 6 (limit: 2272)
Memory: 14.4M (peak: 14.6M)
CPU: 91ms
CGroup: /system.slice/gitlab-runner.service
└─9540 /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --user gitlab-runner
Apr 09 15:59:27 isktw50150-ubuntu-citest systemd[1]: Started gitlab-runner.service - GitLab Runner.
Apr 09 15:59:27 isktw50150-ubuntu-citest gitlab-runner[9540]: Runtime platform arch=amd64 os=linux pid=9540 revision=59dc49a5 version=16.9.2
Apr 09 15:59:27 isktw50150-ubuntu-citest gitlab-runner[9540]: Starting multi-runner from /etc/gitlab-runner/config.toml... builds=0 max_builds=0
Apr 09 15:59:27 isktw50150-ubuntu-citest gitlab-runner[9540]: Running in system-mode.
Apr 09 15:59:27 isktw50150-ubuntu-citest gitlab-runner[9540]:
Apr 09 15:59:27 isktw50150-ubuntu-citest gitlab-runner[9540]: Created missing unique system ID system_id=s_b4db70047986
Apr 09 15:59:27 isktw50150-ubuntu-citest gitlab-runner[9540]: Configuration loaded builds=0 max_builds=1
Apr 09 15:59:27 isktw50150-ubuntu-citest gitlab-runner[9540]: listen_address not defined, metrics & debug endpoints disabled builds=0 max_builds=1
Apr 09 15:59:27 isktw50150-ubuntu-citest gitlab-runner[9540]: [session_server].listen_address not defined, session endpoints disabled builds=0 max_builds=1
Apr 09 15:59:27 isktw50150-ubuntu-citest gitlab-runner[9540]: Initializing executor providers builds=0 max_builds=1
問題なく動作している模様
Gitlab Runnerの登録
説明のURL
Runner認証トークンの説明
GitlabのRunner設定画面の説明
設定
リポジトリ > 設定 > CI/CDで画面表示。「Runner」の項目を開く。「新規プロジェクトRunner」をクリック
「タグ」とあるがこれはGitのタグとは別で、Gitlab CI/CDのタグはRunnerに関連付けられるとの事。
一旦空文字で進める
「タグのないジョブの実行」はチェック入れる
「ランナーを作成」クリック
コマンドをコピペして実行する
$ sudo gitlab-runner register --url http://xx.xx.xx.xx --token glrt-xxxxxxxxxxxxxxx
[sudo] password for username:
Runtime platform arch=amd64 os=linux pid=10458 revision=59dc49a5 version=16.9.2
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
[http://xx.xx.xx.xx]:
Verifying runner... is valid runner=xxxxxxxx
Enter a name for the runner. This is stored only in the local config.toml file:
[isktw50150-ubuntu-citest]:
Enter an executor: docker+machine, kubernetes, instance, docker-windows, docker-autoscaler, custom, shell, ssh, parallels, virtualbox, docker:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"
URLと認証トークンはコピペした値がデフォルトで入っていたのでそのままEnter
「host名」もこの記事外で事前に設定していたホスト名(VM名)が勝手に入ったので、そのままEnter
「executor」は今回はShellにする
config.tomlが存在する事と中身をlessで確認
runnerをrunする
$ sudo less -SN /etc/gitlab-runner/config.toml
$ sudo gitlab-runner run
Runtime platform arch=amd64 os=linux pid=10470 revision=59dc49a5 version=16.9.2
Starting multi-runner from /etc/gitlab-runner/config.toml... builds=0 max_builds=0
Running in system-mode.
Configuration loaded builds=0 max_builds=1
listen_address not defined, metrics & debug endpoints disabled builds=0 max_builds=1
[session_server].listen_address not defined, session endpoints disabled builds=0 max_builds=1
Initializing executor providers builds=0 max_builds=1
Runnerの登録を確認。問題無さそう
パイプラインの作成
ここは一度パイプラインを作成してしまったので初期で実施するときは内容違う可能性があります。
ビルド > パイプラインエディタをクリック
「パイプラインの設定」をクリック
デフォルトのままで「変更をコミットする」をクリック
そのままパイプラインが動作する事を確認
↑「実行中」をクリックしてパイプラインの状況確認
↑「build-job」をクリックしてjobの状況確認
ジョブの内容確認。そのまま待ってパイプライン全てのジョブが完了した事を確認
これでテスト的な動作確認は出来た。
Discussion