书接上文:上文完成了对gitlab-runner的安装,本文介绍一下gitlab-runner注册使用以及注意事项。
-
准备工作
首先确定gitlab-runner的服务器装填是否正常,确定状态为active(running)
[root@etxnode01 ~]# systemctl status gitlab-runner.service
● gitlab-runner.service - GitLab Runner
Loaded: loaded (/etc/systemd/system/gitlab-runner.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2022-03-29 14:12:32 CST; 3s ago
Main PID: 13818 (gitlab-runner)
Tasks: 16
CGroup: /system.slice/gitlab-runner.service
└─13818 /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --user gitlab-runner
- 熟悉gitlab-runner参数
NAME:
gitlab-runner - a GitLab Runner
USAGE:
gitlab-runner [global options] command [command options] [arguments...]
VERSION:
13.8.0 (775dd39d)
AUTHOR:
GitLab Inc. <support@gitlab.com>
COMMANDS:
exec execute a build locally
list List all configured runners
run run multi runner service
register register a new runner
install install service
uninstall uninstall service
start start service
stop stop service
restart restart service
status get status of a service
run-single start single runner
unregister unregister specific runner
verify verify all registered runners
artifacts-downloader download and extract build artifacts (internal)
artifacts-uploader create and upload build artifacts (internal)
cache-archiver create and upload cache artifacts (internal)
cache-extractor download and extract cache artifacts (internal)
cache-init changed permissions for cache paths (internal)
health-check check health for a specific address
read-logs reads job logs from a file, used by kubernetes executor (internal)
help, h Shows a list of commands or help for one command
开始设置:
- register测试runner
必须使用root或者sudo来执行此命令
注意:token可设置为具体仓库,也可使用gitlab服务器对应,token为对应server或者projects的唯一值
如下图所示:
2. 查看已经创建的runner
可通过gitlab-runner list命令
3. gitlab系统配置刚已经创建好的runner ,设置成enable
4. 编写gitlab-ci.yml,用于自动出发ci以及pipeline
需要将gitlab-ci.yml放置到仓库的根目录下,
gitlab-ci.yml测试案例如下:
stages:
- build
- test
job1:
stage: build
script:
- id
jobs2:
stage: test
script:
- cd /home/test
具体参数详解可参考官方文档
提交代码测试jobs状态:
611 git add .
612 git commit -m "test"
613 git push origin master
可查看jobs是否运行成功
注意事项:
一、服务器git版本较低需要更新,至少更新到2.x.x(可直接重新编译安装git)
git源码链接如下:https://mirrors.edge.kernel.org/pub/software/scm/git/
编译过程,本位不在进行详细介绍
二、注意gitlab-ci.yml 中不同的jobs互不干预,如需要共用文件可通过cache缓存
三、scirpt中不可使用source 命令,如source环境变量,请将变量添加到.sh文件中,再通过script去bash sh脚本
变量所依赖的command必须和source再相同文件下,否咋不可用回提示command not find