1、安装runner
sudo yum install gitlab-ci-multi-runner
2、注册runner
sudo gitlab-ci-multi-runner register
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
#这里输入gitlab-ci
服务的运行地址,如:https://gitlab.com/, 回车后
Please enter the gitlab-ci token for this runner
#这里输入gitlab-ci的token,这个token在gitlab的后台,找到runners,里面有个token
Please enter the gitlab-ci description for this runner
#这里输入runner的描述
Registering runner... succeeded
Please enter the executor: shell, docker, docker-ssh, ssh?
#这里选择shell吧
Runner registered successfully.
3、启动runner
单次运行:gitlab-ci-multi-runner run
作为服务运行:
gitlab-runner install --user "root" --service "shell-001" --working-directory="/data" # 这里安装一个服务
gitlab-runner start --service shell-001 #启动这个服务
在gitlab的后台能够查看有runner运行。
4、.gitlab-ci.yml 编辑
这是一个ruby on rails的例子:
before_script:
- git submodule update --init --recursive
- cp /data/database.yml config/database.yml
- sudo chmod +777 /usr/local/rvm/gems/ruby-2.3.0
- gem install bundler
- bundle install
- RAILS_ENV=test bundle exec rake db:migrate
job:
script: "bundle exec rspec"
提交代码应该能够自动运行测试了。