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