GitLab Runner Artifacts 上传失败:完整故障排查与解决文档
故障日期: 2026-11-29
GitLab Runner 版本: 19.6.1
Runner Executor: Docker
代理服务器系统: Ubuntu 22.04
HTTP 代理: Squid 5.9
最终状态: 已解决,Artifacts 上传成功
一、环境架构
本次环境由三部分组成:
- GitLab Runner:通过 Docker 部署,负责执行 CI/CD 任务。
- X-UI:原先使用 X-UI 自带 HTTP 入站作为代理。
- GitLab Server:通过 HTTP 18080 端口提供 GitLab 服务。
最终改为使用 Squid 作为 GitLab Runner 的 HTTP 正向代理。
1.1 服务器信息
| 项目 | 配置 |
|---|---|
| GitLab 地址 | http://gitlab.example.com:18080 |
| GitLab Clone 地址 | http://gitlab.example.com:18080 |
| 代理服务器 | proxy.example.com |
| 原 X-UI HTTP 端口 | 15368 |
| 新 Squid HTTP 端口 | 13128 |
| Squid 版本 | 5.9 |
| Runner 版本 | 19.6.1 |
| Runner Executor | Docker |
| Docker 镜像 | node:22 |
1.2 最终网络架构
GitLab Runner
|
| Docker Executor
|
v
Runner 容器
|
| HTTP Proxy
v
proxy.example.com:13128
|
v
Squid 5.9
|
v
gitlab.example.com:18080
|
v
GitLab Server
|
v
GitLab Workhorse原来的 X-UI HTTP 入站继续保留,但 GitLab Runner 改为使用 Squid。
二、故障现象
最初使用 X-UI 自带 HTTP 入站作为 Runner 代理。
原代理地址:
http://用户名:密码@proxy.example.com:15368GitLab Runner 可以正常执行:
- Docker 镜像拉取。
- Git Clone。
- CI 脚本执行。
- 文件生成。
但是在 Artifacts 上传阶段失败。
错误信息:
Uploading artifacts...
ERROR: Uploading artifacts as "archive" to coordinator...
couldn't execute POST against
http://gitlab.example.com:18080/api/v4/jobs/1451/artifacts
Post "...": EOF
WARNING: Retrying...多次重试后仍然失败。
最初使用 80MB、100MB 文件测试,均出现相同错误。
后来改用只有 1MB 的文件测试,依然失败。
因此,问题不是单纯由大文件上传限制造成的。
三、GitLab Workhorse 日志分析
检查 GitLab Workhorse 日志后,发现关键错误:
handleFileUploads:
extract files from multipart:
persisting multipart file:
unexpected EOF另一次重试:
multipart: NextPart: unexpected EOF对应的请求日志:
method: POST
status: 500
duration_ms: 8576另一次:
method: POST
status: 500
duration_ms: 10278请求来源 IP:
203.0.113.10该 IP 已确认是原 X-UI HTTP 代理的公网出口 IP。
日志分析结论
- Runner 已经成功发起 Artifacts 上传请求。
- 请求已经到达 GitLab Workhorse。
- Workhorse 在读取 multipart 文件内容时出现
unexpected EOF。 - 上传请求体没有完整到达。
- Workhorse 返回 HTTP 500,Runner 最终报告 EOF。
由此排除了 Git Clone、CI 脚本执行以及测试文件生成失败等问题。
当时重点怀疑原 HTTP 代理的请求转发、连接中断或网络链路问题。
四、排除 GitLab CI 配置问题
为了排除原有 CI 工作流的影响,简化 .gitlab-ci.yml,只保留一个测试 Job。
测试配置:
stages:
- test
artifact-test:
stage: test
image: node:22
script:
- rm -rf test-artifacts artifacts-test old-artifacts
- mkdir -p test-artifacts
- echo "GitLab artifact upload test" > test-artifacts/test.txt
artifacts:
paths:
- test-artifacts/
expire_in: 1 hour测试结果:
- Docker 镜像拉取成功。
- Git 仓库拉取成功。
- 脚本执行成功。
- 测试文件生成成功。
- Artifacts 上传失败。
随后增加 1MB 随机文件测试,依然失败。
因此,CI 工作流不是故障原因。
五、原 X-UI HTTP 代理排查
原先使用 X-UI 面板创建 HTTP 入站。
配置:
| 项目 | 值 |
|---|---|
| 协议 | HTTP |
| 监听 IP | 留空 |
| 端口 | 15368 |
| 用户名 | 已配置 |
| 密码 | 已配置 |
使用 curl 测试:
curl -x "http://用户名:密码@proxy.example.com:15368" \
-v --max-time 15 \
"http://gitlab.example.com:18080/users/sign_in" \
-o /dev/null普通 GET 请求可以成功。
但是普通 GET 成功不代表 HTTP multipart POST 文件上传也能正常工作。
因此决定在同一台 Ubuntu 服务器上额外安装 Squid,进行代理对照测试。
六、Ubuntu 安装 Squid 5.9
在 X-UI 所在的 Ubuntu 22.04 服务器上执行。
6.1 安装软件
sudo apt update
sudo apt install -y squid apache2-utils实际安装版本:
squid 5.9-0ubuntu0.22.04.8安装过程中出现 Nginx 服务重启失败提示,但 Squid 本身可以独立配置和启动。
6.2 创建认证账号
sudo htpasswd -c /etc/squid/passwd gitlabtest输入独立的测试密码。
设置权限:
sudo chown proxy:proxy /etc/squid/passwd
sudo chmod 640 /etc/squid/passwd6.3 备份原配置
sudo cp /etc/squid/squid.conf \
/etc/squid/squid.conf.backup6.4 配置 Squid
编辑:
sudo nano /etc/squid/squid.conf配置内容:
http_port 13128
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic realm GitLab Artifact Proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_access deny all
cache deny all
access_log stdio:/var/log/squid/access.log6.5 检查配置
sudo squid -k parse6.6 启动服务
sudo systemctl restart squid
sudo systemctl enable squid
sudo systemctl status squid --no-pager检查端口:
sudo ss -lntp | grep 13128实际结果:
LISTEN 0 256 *:13128
users:(("squid",pid=2328201,fd=11))说明 Squid 已成功监听 13128 端口。
七、Squid 代理测试
在 Ubuntu 服务器本机执行:
curl -x http://gitlabtest:你的密码@127.0.0.1:13128 \
-v --max-time 15 \
http://gitlab.example.com:18080/users/sign_in \
-o /dev/null实际返回:
HTTP/1.1 200 OK
Server: nginx响应头包含:
Via: 1.1 free (squid/5.9)说明:
- Squid 正常工作。
- 用户名密码认证成功。
- GitLab 页面访问成功。
- 请求确实经过 Squid。
八、GitLab Runner 切换 Squid 测试
将 Runner 的 HTTP 代理从原 X-UI 端口切换为 Squid:
http://gitlabtest:新密码@proxy.example.com:13128GitLab 地址保持不变:
http://gitlab.example.com:18080重新执行之前的 Artifacts 测试 Job。
测试结果:Artifacts 上传成功。
这是本次排查最关键的对照结果。
在 GitLab 地址、Runner、CI 测试任务保持不变的情况下,仅切换 HTTP 代理,Artifacts 上传就恢复正常。
因此,问题基本锁定在原 X-UI HTTP 代理链路。
目前尚未确定 X-UI 内部具体哪个机制导致问题,可能涉及 multipart 请求体转发、连接复用或连接中断,不能直接认定某一项内部 Bug。
九、Docker Compose 完整配置
GitLab Runner 使用 Docker Compose 部署。
配置文件:
docker-compose.yml完整配置:
services:
gitlab-runner:
image: gitlab/gitlab-runner:latest
container_name: gitlab-runner
restart: always
environment:
HTTP_PROXY: "http://gitlabtest:替换为新密码@proxy.example.com:13128"
HTTPS_PROXY: "http://gitlabtest:替换为新密码@proxy.example.com:13128"
NO_PROXY: "localhost,127.0.0.1,::1"
http_proxy: "http://gitlabtest:替换为新密码@proxy.example.com:13128"
https_proxy: "http://gitlabtest:替换为新密码@proxy.example.com:13128"
no_proxy: "localhost,127.0.0.1,::1"
volumes:
# Runner 配置持久化到宿主机
- /opt/gitlab-runner:/etc/gitlab-runner
# 允许 Runner 调用宿主机 Docker
- /var/run/docker.sock:/var/run/docker.sock配置说明
/opt/gitlab-runner:持久化 Runner 配置。/var/run/docker.sock:允许 Runner 使用宿主机 Docker。- HTTP_PROXY:HTTP 请求代理。
- HTTPS_PROXY:HTTPS 请求代理。
- NO_PROXY:指定不使用代理的本地地址。
注意:这里没有把 gitlab.example.com 放进 NO_PROXY,因此 GitLab 请求也会经过 Squid。
十、GitLab Runner 完整配置
配置文件位置:
/opt/gitlab-runner/config.toml完整配置:
concurrent = 1
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "84a6b8c6cf34"
url = "http://gitlab.example.com:18080"
clone_url = "http://gitlab.example.com:18080"
id = 7
token = "替换为新的Runner Token"
token_obtained_at = 2026-11-28T11:00:23Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
environment = [
"HTTP_PROXY=http://gitlabtest:替换为新密码@proxy.example.com:13128",
"HTTPS_PROXY=http://gitlabtest:替换为新密码@proxy.example.com:13128",
"NO_PROXY=localhost,127.0.0.1,::1",
"http_proxy=http://gitlabtest:替换为新密码@proxy.example.com:13128",
"https_proxy=http://gitlabtest:替换为新密码@proxy.example.com:13128",
"no_proxy=localhost,127.0.0.1,::1"
]
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.cache.s3]
AssumeRoleMaxConcurrency = 0
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "node:22"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
volume_keep = false
shm_size = 0
network_mtu = 0
environment = [
"HTTP_PROXY=http://gitlabtest:替换为新密码@proxy.example.com:13128",
"HTTPS_PROXY=http://gitlabtest:替换为新密码@proxy.example.com:13128",
"NO_PROXY=localhost,127.0.0.1,::1",
"http_proxy=http://gitlabtest:替换为新密码@proxy.example.com:13128",
"https_proxy=http://gitlabtest:替换为新密码@proxy.example.com:13128",
"no_proxy=localhost,127.0.0.1,::1"
]配置说明
这里保留了两组代理环境变量:
第一组:[[runners]] 下的 environment
用于 Runner 的 Job 环境变量配置。
第二组:[runners.docker] 下的 environment
用于 Docker Executor 创建的构建容器。
Docker Compose 的 environment 则负责 Runner 管理容器自身的环境变量。
三处统一使用 Squid 的 HTTP 代理地址。
clone_url 保持 GitLab 的 HTTP 地址,不会强制切换 HTTPS CDN。
注意:如果代理密码包含 @、:、/、# 等 URL 特殊字符,需要进行 URL 编码后再放入代理 URL。
十一、应用 Runner 配置
在 Docker Compose 文件所在目录执行:
docker compose up -d --force-recreate gitlab-runner检查容器状态:
docker ps | grep gitlab-runner检查 Runner 注册状态:
docker exec gitlab-runner gitlab-runner verify检查 Runner 容器代理环境变量:
docker exec gitlab-runner sh -lc 'env | grep -i proxy'查看 Runner 日志:
docker logs --tail 50 gitlab-runner十二、最终验证
使用之前的简单测试任务:
stages:
- test
artifact-test:
stage: test
image: node:22
script:
- rm -rf test-artifacts artifacts-test old-artifacts
- mkdir -p test-artifacts
- echo "GitLab artifact upload test" > test-artifacts/test.txt
artifacts:
paths:
- test-artifacts/
expire_in: 1 hour重点观察:
Uploading artifacts...
Uploading artifacts as "archive" to coordinator...成功时应返回 HTTP 201 Created。
十三、安全注意事项
- 原先的 X-UI 代理密码已经在聊天内容中暴露,建议更换。
- Squid 测试账号密码也已经暴露,建议重新设置独立密码。
- 原 Runner Token 已经在聊天内容中暴露,建议在 GitLab 中轮换 Runner Token,并更新 config.toml。
- Squid 13128 端口不要向整个互联网开放。
- 建议使用 UFW 或云平台防火墙,只允许 Runner 所在服务器公网 IP 访问 13128。
- 不要把代理密码和 Runner Token 提交到 Git 仓库。
- 保留
/etc/squid/squid.conf.backup,方便恢复。 - 暂时保留原 X-UI HTTP 入站 15368,不需要因为本次问题而删除。
注意 Docker 镜像拉取: Runner 容器中的 HTTP_PROXY 不会自动配置宿主机 Docker daemon。node:22 等镜像的拉取走的是宿主机 Docker 网络,需要另外配置宿主机 Docker daemon 代理(如果镜像拉取也需要代理)。
十四、常用运维命令
查看 Squid 状态
sudo systemctl status squid --no-pager重启 Squid
sudo systemctl restart squid查看 Squid 实时访问日志
sudo tail -f /var/log/squid/access.log查看 Squid 错误日志
sudo tail -f /var/log/squid/cache.log查看 13128 端口
sudo ss -lntp | grep 13128检查 Squid 配置
sudo squid -k parse重启 GitLab Runner
docker restart gitlab-runner查看 Runner 日志
docker logs --tail 100 gitlab-runner十五、最终总结
本次故障表现为 GitLab Runner Artifacts 上传失败,Runner 返回 EOF,GitLab Workhorse 报告 multipart unexpected EOF。
经过多次测试,确认:
- Git Clone 正常。
- CI Job 执行正常。
- 1MB 和较大的 Artifacts 均无法通过原 X-UI HTTP 代理成功上传。
- 普通 HTTP GET 请求可以正常通过原代理。
- 安装 Squid 5.9 后,普通 HTTP GET 请求成功。
- 将 Runner 代理切换到 Squid 13128 后,Artifacts 上传成功。
最终采用以下方案:
使用 Ubuntu 22.04 + Squid 5.9 + HTTP Basic Authentication,为 GitLab Runner 提供 HTTP 正向代理。
原 X-UI HTTP 入站继续保留,GitLab Runner 统一使用 Squid 13128。
最终故障状态:已解决。
故障定位:原 X-UI HTTP 代理链路存在 Artifacts 上传转发问题,具体内部机制尚未确认。