Gitlab CI 入门实例

Gitlab CI 要能跑起来,需要两大部分的支持,一个是Gitlab Server,另外一个是Gitlab Runner,执行具体的任务是在Runner上面,工作调度,安排是有Gitlab Server完成。可以理解成一个是老板,一个是真正干具体事情的员工的关系。

本文主要关注如何建立Runner,并且将Runner与Gitlab Server建立联系,为Gitlab Server使用

首先确保Gitlab server已经安装, 再给Runner找一台linux服务器, 然后就可以开始了。

 

1. 添加GitLab的官方仓库

# For Debian/Ubuntu/Mint curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash

2. 安装GitLab Runner

# For Debian/Ubuntu/Mint sudo apt-get install gitlab-runner

3. 注册Runners

3.1 在GitLab页面找到Runners settings,点击右边的Expand按钮

Gitlab CI 入门实例

3.2 往下面拉页面,可以看到如下截图, 记录第2和第3点的URL和token

Gitlab CI 入门实例

3.3 注册Runner

参考:https://docs.gitlab.com/runner/register/index.html

sudo gitlab-runner register

 

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )

从3.2获取的URL

 

Please enter the gitlab-ci token for this runner

从3.2获取的token

 

Please enter the gitlab-ci description for this runner

[hostname] my-runner

 

Please enter the gitlab-ci tags for this runner (comma separated):

my-tag,another-tag

 

Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:

shell

3.4 启动Runner

(venv)..$ systemctl start gitlab-runner

(venv)..$ gitlab-runner run

3.5 在gitlab 页面找到Runner,进入3.1的Runner 页面, 在URL 和token下面有如下图所示的Runner提示

Gitlab CI 入门实例

如果上图中不是绿色按钮,说明runner启动有问题

在Runner服务器上面,执行 “gitlab-runner verify”命令,启动Runner,gitlab Runner页面出现绿色按钮, Runner可以正常使用

Gitlab CI 入门实例

3.6 修改.gitlab-ci.yml 文件,当有新的代码提交,就会执行文件里面的内容

 

一个简单的实例就这样搭好了 :)

 

 

 

 

参考文档: https://docs.gitlab.com/runner/install/linux-repository.html

                   https://blog.51cto.com/flyfish225/2156602?source=dra