gitlab-ci-runner安裝
前言
什麽是CI/CD?
CI (Continuous Integration) 持續集成, CD (Continuous Delivery) 持續部署
個人理解
本地開發代碼, 提交遠程倉庫
倉庫接收到提交操作,進入持續集成, 包括編譯,自動化測試 (CI)
編譯測試成功後,部署到線上服務器(CD)
gitlab-runner 介紹
gitlab 提供了一個持續集成的服務, 如果你在項目倉庫裏面加入.gitlab-ci.yml文件 同時給項目配置了gitlab-runner, 那麽每一次push commit, 都會觸發你的 CI pipeline (持續集成管道)
安裝gitlab-runner
官方文檔
代理安裝 gitlab-runner
如果機器能夠正常訪問外網,那麽查閱官方文檔進行安裝
一般來說,內網與外網是處於隔斷的情況,但是可以通過http代理服務器,允許內網訪問外網的資源。
假設代理服務器機器的ip為: http://192.168.1.100:8000
具體步驟:
編輯 yum.conf
sudo vi /etc/yum.conf # 追加一行 proxy=http://192.168.1.100:8000 #添加 GitLab's official repository (yum倉庫) http_proxy=http://192.168.1.100:8000 curl -L -x $http_proxy https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sed "s#curl -sSf#curl -x $http_proxy -sSf#g" > script.rpm.sh sudo bash script.rpm.sh
下載安裝gitlab
# 查看gitlab-runner的版本 yum list gitlab-runner --showduplicates | sort -r gitlab-runner.x86_64 10.5.0-1 runner_gitlab-runner gitlab-runner.x86_64 10.4.0-1 runner_gitlab-runner gitlab-runner.x86_64 10.3.1-1 runner_gitlab-runner gitlab-runner.x86_64 10.3.0-1 runner_gitlab-runner gitlab-runner.x86_64 10.2.1-1 runner_gitlab-runner gitlab-runner.x86_64 10.2.0-1 runner_gitlab-runner gitlab-runner.x86_64 10.1.1-1 runner_gitlab-runner gitlab-runner.x86_64 10.1.0-1 runner_gitlab-runner gitlab-runner.x86_64 10.0.2-1 runner_gitlab-runner gitlab-runner.x86_64 10.0.1-1 runner_gitlab-runner gitlab-runner.x86_64 10.0.0-1 runner_gitlab-runner # 指定安裝某個版本 sudo yum install gitlab-runner-10.1.1-1 -y
安裝完成後, 出現一個/home/gitlab-runner 文件夾
gitlab-runner 命令
主要的命令操作有如下: install, start, stop, status, register, unregister
install 命令
安裝配置 gitlab-runner, 如果使用yum install 則會默認安裝
# --user 用戶名
# --working-directory 工作目錄
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
start 命令
sudo gitlab-runner start, 啟動服務
stop 命令
sudo gitlab-runner stop, 關閉服務
status 命令
sudo gitlab-runner status, 查看服務運行狀態
在倉庫中查閱CI / CD Setting, 得到 CI token
sudo gitlab-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://gitlab.com/
Please enter the gitlab-ci token for this runner:
gHKt7inn3nBzJ2m5gx-P
Please enter the gitlab-ci description for this runner:
hostname
Please enter the gitlab-ci tags for this runner (comma separated):
node,test
Whether to run untagged builds [true/false]:
true
Whether to lock the Runner to current project [true/false]:
false
Registering runner... succeeded runner=gHKt7inn
Please enter the executor: docker+machine, kubernetes, docker-ssh, ssh, shell, virtualbox, docker-ssh+machine, docker, parallels:
shell
註冊後使用 gitlab-runner list 查閱配置
sudo gitlab-runner list
Listing configured runners ConfigFile=/etc/gitlab-runner/config.toml
hostname Executor=shell Token=token URL=https://gitlab.com/
註冊後,gitlab 頁面將出現一個運行的runner
gitlab-runner unregister 命令
通過 url 和 token 取消註冊 gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n
通過name取消註冊 gitlab-runner unregister --name test-runner
刪除所有註冊runner gitlab-runner unregister --all-runners
gitlab-ci-runner安裝