|
GitLab Runnerは、ジョブを実行し、その結果をGitLabに返すためのオープンソースプロジェクトです。GitLab Runnerは、ジョブのオーケストレーションを行うGitLabに付属するオープンソースの継続的インテグレーションサービスであるGitLab CIと連携して動作します。 インストール要件GitLab RunnerはGo言語で記述されており、バイナリとして実行できるため、言語の制約はありません。GNU/Linux、macOS、Windowsの各オペレーティングシステムで動作するように設計されています。他のオペレーティングシステムでGoバイナリをコンパイルできる限り、他のオペレーティングシステムでも動作する可能性が高いでしょう。 Dockerを使用する場合は、最新バージョンをインストールしてください。GitLab Runnerには少なくともDocker v1.13.0が必要です。 GitLab Runner のバージョンは GitLab のバージョンと同期する必要があります。 GitLab Runnerは、GNU/Linux、macOS、FreeBSD、Windowsにインストールして使用できます。Dockerを使用してインストールすることも、バイナリを手動でダウンロードすることも、GitLabが提供するrpm/debパッケージのリポジトリを使用することもできます。 CentOSベースのインストールcurl -LJO https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_<arch>.rpm rpm -i gitlab-runner_<arch>.rpm rpm -Uvh gitlab-runner_<arch>.rpm
macOSシステムに基づくインストールsudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/v12.6/binaries/gitlab-runner-darwin-amd64 sudo chmod +x /usr/local/bin/gitlab-runner gitlab-runner install gitlab-runner start
Docker上で実行mkdir ~/data/gitlab-runner/config docker run --rm -t -id -v ~/data/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:v12.9.0
GitLabランナー登録- shared: プラットフォーム プロジェクト (GitLab) 全体を実行するジョブ。
- グループ: 特定のグループ内のすべてのプロジェクトを実行するジョブ。
- 特定: 指定されたプロジェクト ジョブを実行します。
- 州
- ロックされています: プロジェクト/ジョブを実行できません。
- 一時停止: ジョブを一時停止し、実行されません。
共有タイプのランナートークンを取得するタイプグループのランナートークンを取得するグループに移動 -> 設定 -> CI/CD -> ランナー -> グループランナー 特定のタイプのランナートークンを取得する特定のプロジェクト -> 設定 -> CI/CD -> ランナー -> 特定のランナーに移動します。 コンテナのインタラクティブ登録を開始するdocker run --rm -t -i -v ~/data/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:v12.6.0 register Runtime platform arch=amd64 os=linux pid=6 revisinotallow=ac8e767a versinotallow=12.6.0 Running in system-mode. Please enter the gitlab-ci coordinator URL (eg https://gitlab.com/): http://192.168.1.105 Please enter the gitlab-ci token for this runner: 4tutaeWWL3srNEcmHs1s Please enter the gitlab-ci description for this runner: [00e4f023b5ae]: devops-service-runner Please enter the gitlab-ci tags for this runner (comma separated): build Registering runner... succeeded runner=4tutaeWW Please enter the executor: parallels, virtualbox, docker-ssh+machine, kubernetes, docker+machine, custom, docker, docker-ssh, shell, ssh: shell Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
非対話型登録docker run -itd --rm -v ~/data/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:v12.6.0 register \ --non-interactive \ --executor "shell" \ --url "http://192.168.1.200:30088/" \ --registration-token "JRzzw2j1Ji6aBjwvkxAv" \ --description "devops-runner" \ --tag-list "build,deploy" \ --run-untagged="true" \ --locked="false" \ --access-level="not_protected"
効果: 一般的なコマンド起動コマンド: gitlab-runner --debug <command> #调试模式排查错误特别有用。 gitlab-runner <command> --help #获取帮助信息gitlab-runner run #普通用户模式配置文件位置~/.gitlab-runner/config.toml sudo gitlab-runner run # 超级用户模式配置文件位置/etc/gitlab-runner/config.toml 登録コマンド: gitlab-runner register #默认交互模式下使用,非交互模式添加--non-interactive gitlab-runner list #此命令列出了保存在配置文件中的所有运行程序gitlab-runner verify #此命令检查注册的runner是否可以连接,但不验证GitLab服务是否正在使用runner。--delete 删除gitlab-runner unregister #该命令使用GitLab取消已注册的runner。 #使用令牌注销gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n #使用名称注销(同名删除第一个) gitlab-runner unregister --name test-runner #注销所有gitlab-runner unregister --all-runners サービス管理: gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner # --user指定将用于执行构建的用户#`--working-directory 指定将使用**Shell** executor 运行构建时所有数据将存储在其中的根目录gitlab-runner uninstall #该命令停止运行并从服务中卸载GitLab Runner。 gitlab-runner start #该命令启动GitLab Runner服务。 gitlab-runner stop #该命令停止GitLab Runner服务。 gitlab-runner restart #该命令将停止,然后启动GitLab Runner服务。 gitlab-runner status #此命令显示GitLab Runner服务的状态。当服务正在运行时,退出代码为零;而当服务未运行时,退出代码为非零。 パイプラインの実行stages: - build - deploy build: stage: build tags: - build only: - master script: - echo "mvn clean " - echo "mvn install" deploy: stage: deploy tags: - deploy only: - master script: - echo "hello deploy"
GitLab CIは、開発と運用を同じ担当者が担当するアジャイル開発などのDevOpsプロフェッショナルにとって非常に便利な開発手法です。Jenkins CIは、明確な責任分担、構成とコードの分離、豊富なプラグインを備えているため、複数の役割を持つチームに適しています。 |