参考文档
安装
下载安装包
默认是下载最新的,需要找跟 gitlab 版本相匹配的,不然容易出问题
下载地址
我要下载的是 12.10.0 版本,如果需要其它版本,替换下面地址中的版本号即可。
https://s3.amazonaws.com/gitlab-runner-downloads/v12.10.0/binaries/gitlab-runner-windows-amd64.exe
创建一个目录:eg C:\GitLab-Runner
,将上面的 exe 放进来,最好重新改个名字,方便执行 ./gitlab-runner 命令
核心步骤
执行下面命令可以查看 gitlab-runner 有下面一些命令,核心的有 3 个步骤:注册、安装、启动
# gitlab-runner
Runtime platform arch=amd64 os=linux pid=24873 revision=c553af1a version=12.10.0
NAME:
gitlab-runner - a GitLab Runner
USAGE:
gitlab-runner [global options] command [command options] [arguments...]
VERSION:
12.10.0 (c553af1a)
AUTHOR:
GitLab Inc. <support>
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)
health-check check health for a specific address
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--cpuprofile value write cpu profile to file [$CPU_PROFILE]
--debug debug mode [$DEBUG]
--log-format value Choose log format (options: runner, text, json) [$LOG_FORMAT]
--log-level value, -l value Log level (options: debug, info, warn, error, fatal, panic) [$LOG_LEVEL]
--help, -h show help
--version, -v print the version
注册
# 根据提示输入 gitlab 地址,token,执行器模式 shell
./gitlab-runner.exe register
安装
该步骤的目的是为了将 gitlab-runner 安装为 service 服务
# 根据提示输入 gitlab 地址,token,执行器模式 shell
./gitlab-runner.exe install
启动
./gitlab-runner.exe start
# 查看状态
./gitlab-runner.exe status
可能出现的问题
- windows中shell的默认运行默认是powershell, powershell模式下脚本不能按原来的shell模式编写。
- 在runner可执行文件的同级目录有个config.toml文件,可以修改shell的配置为bash(shell模式支持cmd, sh, bash, powershell等)。
- 在windows中,runner start完成后需要把runner注册到当前的系统用户Administrator中,否则有的命令找不到(例如:opdev,虽然在环境变量配置了,但是gitlab-runner 运行的时候找不到这命令)。具体方法为:任务管理器->服务->打开服务->找到gitlab-runner这个服务->属性->登录
hi devops