windows 安装 gitlab-runner

gitlab-runner

一、安装

安装 gitlab runner 文档参考地址

1、下载exe执行文件

我这里是 win64

https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-windows-amd64.exe

2、创建 gitlab-runner 目录,并进入目录

cd gitlab-runner

3、将上面下载的 gitlab-runner-windows-amd64.exe 放到 gitlab-runner 目录

# 当然不改也可以,这里改名是为了后面执行命令方便
改名成:gitlab-runner.exe

注意后续使用 .gitlab-runner.exe 执行的命令都需要使用管理员身份运行
否则会被拒绝

4、安装 gitlab-runner

使用系统账号安装gitlab-runner

  • 这里使用默认系统用户安装,可能导致各种资源找不到或者权限问题
  • 此时可以
    • 右键我的电脑、或者打开文管理器-右键此电脑
    • 选择管理菜单
    • 选择服务和应用程序-服务
    • 找到 gitlab-runner 服务-右键选择属性-选择登陆tab-登陆身份选择此账户,浏览选择日常开发时候所用到的账户
    • 设置好后,重启gitlab-runner 服务即可
.gitlab-runner.exe install

使用指定账户安装gitlab-runner

  • 重要的事情说三遍!!!重要的事情说三遍!!!重要的事情说三遍!!!大部分问题是这个没做好导致的!!!最好指定当前日常开发时候所用的用户,这样可以明确指定gitlab-runner使用当前开发用户的git、yarn、npm、node 等资源,而不会导致各种资源缺少或者权限问题
.gitlab-runner.exe install --user your-username --password your-password

二、注册 runner

registering runners 文档参考地址

1、注册一个gitlab-runner

注册的 gitlab-runner 分为共享runner和特定runner
共享runner,所有gitalb项目都可用
特定runner,只对指定项目生效

这里我们注册特定runner

.gitlab-runner.exe register

注册时候需要填写该runner关联的url和token,以及runner的描述和标签tags,还有runner执行时候的脚本类型
.gitlab-ci.yml 中执行任务中的tags,指定要运行的runner

url 和 token 在 gitlab 项目 ---> 设置 ---> CI/CD ---> Setup a specific Runner manually 获取

回到 gitlab 页面,刷新即可看到注册的 runner

三、构建

1、注册好后,在项目中添加 .gitlab-ci.yml 文件

在里面定义gitlab-runner所要执行的逻辑:

  • runner任务触发的时机
  • runner任务触发时候执行的脚本
  • 等等

2、使用shell executor,构建项目时候,项目将会被克隆到以下目录:

<working-directory>/builds/<short-token>/<concurrent-id>/<namespace>/<project-name>

例如

D:gitrunneruilds58820adaweb-securewebapp

项目的caches被存储到

<working-directory>/cache/<namespace>/<project-name>

变量解释:

<working-directory>:runner当前执行的目录或者使用--working-directory指定的目录
<short-token>:runner的token前8位
<concurrent-id>:一个唯一的number,用于区别job,从0开始
<namespace>:项目拥有者的名称
<project-name>:项目名

四、gitlab-runner 常用命令

注意使用 .gitlab-runner.exe 执行的命令都需要使用管理员身份运行
否则会被拒绝

安装

.gitlab-runner.exe install

注册

.gitlab-runner.exe register

启动

.gitlab-runner.exe start

停止

.gitlab-runner.exe stop

更新

1、.gitlab-runner.exe stop
2、下载新版的gitlab-runner程序,替换掉当前的gitlab-runner.exe
3、.gitlab-runner.exe start

卸载

.gitlab-runner.exe stop
.gitlab-runner.exe uninstall
cd ..
rmdir /s gitlab-runner

查看runner状态

.gitlab-runner.exe status

查看runner列表

.gitlab-runner.exe list
都读到最后了、留下个建议如何
原文地址:https://www.cnblogs.com/linjunfu/p/14760750.html