You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用gitlab-runner报GIT_CONFIG_PARAMETERS格式错误排查

问题现象

使用gitlab-runner执行CI任务拉取代码时,触发error: bogus format in GIT_CONFIG_PARAMETERS错误,报错日志如下:

Running with gitlab-runner 14.3.3 (febb2a09)
  on MACHINE 4nC48mnS
Preparing the "shell" executor 00:00
Preparing environment 00:01
Running on MACHINE...
Getting source from Git repository 00:00
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /home/gitlab-runner/builds/4nC48mnS/0/dev/test/.git/
error: bogus format in GIT_CONFIG_PARAMETERS
fatal: unable to parse command-line config
ERROR: Job failed: exit status 1
排查记录
  1. 执行逻辑核查
    排查gitlab-runner拉取代码的实现逻辑发现,程序会在git fetch命令前拼接-c参数传入自定义HTTP User-Agent,核心拼接逻辑如下:
userAgent := fmt.Sprintf("http.userAgent=%s %s %s/%s", v.Name, v.Version, v.OS, v.Architecture)

fetchArgs := []string{"-c", userAgent, "fetch", "origin"}
fetchArgs = append(fetchArgs, build.GitInfo.Refspecs...)
if depth > 0 {
    fetchArgs = append(fetchArgs, "--depth", strconv.Itoa(depth))
}

fetchArgs = append(fetchArgs, build.GetGitFetchFlags()...)

w.Command("git", fetchArgs...)

拼接完成后实际执行的命令中,http.userAgent的参数值包含多处空格。手动执行带-c参数的fetch命令可直接复现错误:

# git -c http.userAgent=gitlab-runner fetch origin
error: bogus format in GIT_CONFIG_PARAMETERS
fatal: unable to parse command-line config
  1. 环境版本信息
  • gitlab : 14.3.3
  • gitlab-runner : 14.3.3
  • git : 2.35.2
  • 操作系统 : RHEL8.4
  1. 配置与环境变量检查
    6月23日补充排查结果:
  • 系统层面未设置GIT_CONFIG_PARAMETERS环境变量
  • 仓库.git/config配置无异常,检查输出如下:
# echo $GIT_CONFIG_PARAMETERS

# test -v GIT_CONFIG_PARAMETERS
# echo $?
1
# cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[user]
        name = aaaaaa@example.com
        password = "aaaaaa"
[remote "origin"]
        url = http://githostname/dev/test.git
        fetch = +refs/heads/*:refs/remotes/origin/*
  1. 功能验证
    不带-c参数直接执行git fetch origin可正常拉取代码,添加-c参数则稳定复现错误:
# git fetch origin
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 15 (delta 0), reused 0 (delta 0), pack-reused 6
Unpacking objects: 100% (15/15), 1.22 KiB | 52.00 KiB/s, done.
From http://githostname/dev/test
 * [new branch]      main       -> origin/main
# git -c http.userAgent=gitlab-runner  fetch origin
error: bogus format in GIT_CONFIG_PARAMETERS
fatal: unable to parse command-line config
根本原因

Git 2.35版本更新了GIT_CONFIG_PARAMETERS的解析逻辑,对通过-c参数传入的配置项格式校验收紧,要求包含特殊字符、空格的配置值必须按规则做转义处理;而14.3.3版本的GitLab Runner在构造git fetch命令时,拼接的http.userAgent配置值包含空格却未做合规转义,在该版本Git环境下会被判定为非法参数格式,触发报错,属于典型的跨版本兼容性问题。

可行解决方案
  • 升级GitLab Runner至14.9及以上版本:官方已在后续版本修复该参数转义缺陷,可原生兼容Git 2.35+的解析规则,为长期最优方案
  • 降级Git版本至2.34.x及更早稳定版:回退到解析规则变更前的Git版本,可直接适配现有14.3.3版本的GitLab Runner,适合不方便升级Runner的场景
  • 临时规避配置:在Runner部署节点提前为Git全局设置http.userAgent参数,同时修改Runner配置关闭任务执行时动态注入User-Agent的逻辑,避免拉取代码环节拼接-c传参,可快速恢复任务执行

内容的提问来源于stack exchange,提问作者soireu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.28 18:45:32