Gitlab-CI实现组件自动推送

一、安装gitlab-runner

1.1 下载gitlab-runner

bash 复制代码
#查看自己的系统
go env GOARCH

#amd64下载
sudo curl --output $GOROOT/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64"

#arm64下载
sudo curl --output $GOROOT/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64"

sudo chmod +x $GOROOT/bin/gitlab-runner
cd $GOROOT/bin
gitlab-runner install
gitlab-runner start
#查看gitlab-runner是否正常启动
gitlab-runner status

通过终端下载比较慢,建议通过浏览器下载。

amd64下载地址:https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64

arm64下载地址:https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64

1.2 gitlab-runner注册到服务器

注册过程中要用到gitlab-ci的URL和Token

获取gitlab-ci的Token: 项目主页 -> Sttings -> CI/CD -> Runners Expand

注册Runner

bash 复制代码
0.---开始注册 [root@iZ2zectqga6hz17svze9jdZ ~]# gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=18056 revision=43b2dc3d version=15.4.0
Running in system-mode.                            
                                                   
1--- 叫你输入服务器地址:Enter the GitLab instance URL (for example, https://gitlab.com/):
http://gitlab.cfuture.shop/   // 这里填你的服务器地址
2---叫你输入token: Enter the registration token:
6UKvXWMU69gxFFyTUyvM
3---叫你输入runner描述Enter a description for the runner:
[iZ2zectqga6hz17svze9jdZ]: seenew-ops
4---叫你输入tags的名称:Enter tags for the runner (comma-separated):
seenew-ops
5--这里照我下面写即可-Enter optional maintenance note for the runner:
runner by shell
Registering runner... succeeded                     runner=GR13489417QtPoCmD
6---这里照我下面写即可Enter an executor: custom, docker-ssh, ssh, docker+machine, kubernetes, docker, parallels, shell, virtualbox, docker-ssh+machine:
shell  // 输入shell
Runner registered successfully. // 这里提示成功了

激活Runner

bash 复制代码
gitlab-runner verify

二、通过gitlab-ci推送chart

项目内新建一个.gitlab-ci.yml文件,内容如下:

bash 复制代码
stages:
  - deploy

deploy-job:
  tags:
    - seenew-ops
  stage: deploy
  script:
    - sh $GOPATH/src/seenew-ops-k8s/mdcl/mdcl-ci.sh

tags是当前Job的标记,这个tags关键字是很重要,因为gitlab的runner会通过tags去判断能否执行当前这个Job

提交代码,查看是否执行gitlab-ci

三、踩坑记录

3.1 job一直pending,没有Runner处理

● 首先考虑的是不是Runner没有激活,如果没有那么按上面方式处理

● 还可能是tag没有匹配到,Runner注册时是要填写绑定tag的,如果你在YML里面编写Job没有带上tag是不会有自定义Runner来处理。解决方法:给Job加tags

● Runner状态为stop

3.2 Runner启动报错

原因:安装的时候放在/usr/local/bin目录下,启动时权限不够,修改日志输出的目录。如下以我本地为例:

bash 复制代码
原因:安装的时候放在/usr/local/bin目录下,启动时权限不够,修改日志输出的目录。如下以我本地为例:

修改runner的安装地址和日志输出路径(原来是在/usr/local/bin目录)

修改完成后执行

bash 复制代码
launchctl unload /Users/jiangjunyu/Library/LaunchAgents/gitlab-runner.plist
launchctl load -w /Users/jiangjunyu/Library/LaunchAgents/gitlab-runner.plist
gitlab-runner stop
gitlab-runner start
gitlab-runner status
相关推荐
张居斜9 小时前
GitHub Actions + 阿里云 OSS:OIDC 免密同步构建产物
github·oss·llm-wiki
用户32283600844712 小时前
python-rapidjson:用 C++ 速度处理 JSON 的 Python 库
github
逛逛GitHub12 小时前
4 个比较实用的 GitHub 开源项目,浅浅的收藏一波。
github
Hommy8813 小时前
【剪映小助手】添加贴纸接口(Add Sticker)
后端·github·剪映小助手·视频剪辑自动化·剪映api
2601_9618451516 小时前
粉笔行测5000题电子版|pdf|解析
pdf·新媒体运营·github·个人开发·内容运营·规格说明书·极限编程
用户7735300845119 小时前
gorillamux:Go语言路由库的实用选择
github
BBWEYY终身尊贵会员19 小时前
2026年6月四款建站工具怎么选?BBWEYY、比文云、GitHub Copilot、Dreamweaver 简明对比
github·copilot·dreamweaver
DogDaoDao20 小时前
【GitHub】CL4R1T4S:AI 系统提示词的透明革命
人工智能·python·ai·大模型·github·ai agent·cl4r1t4s
CHENG-JustDoIt20 小时前
AI工具 | 爆火开源项目Odysseus AI 工作台:从项目介绍、部署情况及其使用等多方位分析指南(含详细步骤)
大数据·人工智能·windows·python·ai·开源·github
MicrosoftReactor20 小时前
技术速递|从一次性提示到标准化工作流:如何在 GitHub Copilot CLI 中使用自定义智能体
github·copilot·cli·智能体