什麼是CI/CD?
CI (Continuous Integration) 持續集成, CD (Continuous Delivery) 持續部署html
我的理解node
gitlab 提供了一個持續集成的服務, 若是你在項目倉庫裏面加入.gitlab-ci.yml
文件 同時給項目配置了gitlab-runner, 那麼每一次push commit, 都會觸發你的 CI pipeline (持續集成管道)linux
官方安裝文檔git
若是機器可以正常訪問外網,那麼查閱官方文檔進行安裝docker
通常來講,內網與外網是處於隔斷的狀況,可是能夠經過http代理服務器,容許內網訪問外網的資源。
假設代理服務器機器的ip爲: http://192.168.1.100:8000
shell
具體步驟:bash
編輯 yum.conf服務器
sudo vi /etc/yum.conf # 追加一行 proxy=http://192.168.1.100:8000
添加 GitLab's official repository (yum倉庫)ssh
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
下載安裝gitlabcurl
# 查看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
文件夾
主要的命令操做有以下: 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
, 查看服務運行狀態
register 命令
註冊一個任務,這個屬於gitlab-runner
比較重要的命令, 咱們須要結合一個實際的案例進行演示,
項目倉庫地址: https://gitlab.com/liyanlong/...
在倉庫中查閱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 命令
gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n
gitlab-runner unregister --name test-runner
gitlab-runner unregister --all-runners