抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

GitLab Runner 是一个与 GitLab CI/CD 配合使用以在管道中运行作业的应用程序。您可以选择在拥有或管理的基础设施上安装 GitLab Runner 应用程序。GitLab Runner 还可在 Docker 容器内运行或部署到 Kubernetes 集群中。

下载

如果是 Debian 或 Ubuntu,运行以下命令:

1
wget https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb

如果是 CentOS 或 Red Hat Enterprise Linux,运行以下命令:

1
wget https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_amd64.rpm

安装

如果是 Debian 或 Ubuntu,运行以下命令:

1
dpkg -i gitlab-runner_amd64.deb

如果是 CentOS 或 Red Hat Enterprise Linux,运行以下命令:

1
rpm -i gitlab-runner_amd64.rpm

如若出现以下错误提示,说明 Git 和 cURL 命令未安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@dusays:~# dpkg -i gitlab-runner_amd64.deb
(Reading database ... 198268 files and directories currently installed.)
Preparing to unpack gitlab-runner_amd64.deb ...
Unpacking gitlab-runner (14.0.1) over (14.0.1) ...
dpkg: dependency problems prevent configuration of gitlab-runner:
gitlab-runner depends on git; however:
Package git is not installed.
gitlab-runner depends on curl; however:
Package curl is not installed.

dpkg: error processing package gitlab-runner (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
gitlab-runner

运行下面的命令安装 Git 和 cURL:

1
2
apt -y install git curl # for Debian or Ubuntu
yum -y install git curl # for CentOS or Red Hat Enterprise Linux

注册

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Runtime platform                                    arch=amd64 os=linux pid=5349 revision=c1edb478 version=14.0.1
Running in system-mode.

Enter the GitLab instance URL (for example, https://gitlab.com/):
https://dusays.com/
Enter the registration token:
xxxxxxxxxxxxxxxxxxxx
Enter a description for the runner:
[dusays]:
Enter tags for the runner (comma-separated):

Registering runner... succeeded runner=FKPxD53P
Enter an executor: virtualbox, docker+machine, kubernetes, custom, parallels, shell, ssh, docker, docker-ssh, docker-ssh+machine:
custom
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

注意:首先输入 GitLab 的地址,然后复制项目——设置——CI/CD 中找到 token 值,再者输入 runner 的描述用于分辨,接着输入 runner 的 tags 可为空,最后设置执行方式即可。

设置

进入 GitLab 项目中,按照下图所示找到 runner 配置文件添加处,参考下面代码进行配置:

参考代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
stages:
- build
- test

build-code-job:
stage: build
script:
- echo "Check the ruby version, then build some Ruby project files:"
- ruby -v
- rake

test-code-job1:
stage: test
script:
- echo "If the files are built successfully, test some files with one command:"
- rake test1

test-code-job2:
stage: test
script:
- echo "If the files are built successfully, test other files with a different command:"
- rake test2

评论