GitLab CI执行bower install遇ECMDERR错误(git退出码128)排查求助
GitLab CI中Bower Install报ECMDERR(退出码128)的排查指导
问题详情
维护旧项目时,在GitLab CI环境执行bower install频繁出现以下错误,且报错的仓库不固定:
ECMDERR Failed to execute "git ls-remote --tags --heads https://github.com/angular/bower-angular-sanitize.git", exit code of #128
本地使用相同镜像执行相同命令可正常完成,已尝试以下配置但未解决:
- 设置Git全局用户名和邮箱
- 将
git://协议替换为https://
已执行的配置命令
git config --global user.name "${GITLAB_USER_NAME}" git config --global user.email "${GITLAB_USER_EMAIL}" git config --global url."https://".insteadOf git://
Bower安装日志片段
执行bower install --json得到的部分错误输出:
, { "level": "info", "id": "resolved", "message": "https://github.com/angular-ui/angular-google-maps.git#065568aa32", "data": { "endpoint": { "name": "angular-google-maps", "source": "angular-google-maps", "target": "065568aa32954afa2c9de917542163cd5d3f2b5a" }, "resolver": { "name": "angular-google-maps", "source": "https://github.com/angular-ui/angular-google-maps.git", "target": "065568aa32954afa2c9de917542163cd5d3f2b5a" } } } , { "code": "ECMDERR", "details": "", "exitCode": 128, "data": { "endpoint": { "name": "angular-datatables", "source": "angular-datatables", "target": "~0.6.x" }, "resolver": { "name": "angular-datatables", "source": "https://github.com/l-lin/angular-datatables.git", "target": "~0.6.x" } }, "id": "ECMDERR", "level": "error", "message": "Failed to execute \"git ls-remote --tags --heads https://github.com/l-lin/angular-datatables.git\", exit code of #128\n", "stacktrace": "Error: Failed to execute \"git ls-remote --tags --heads https://github.com/l-lin/angular-datatables.git\", exit code of #128\n\n at createError (/var/www/.npm/_npx/53/lib/node_modules/bower/lib/util/createError.js:4:15)\n at ChildProcess.<anonymous> (/var/www/.npm/_npx/53/lib/node_modules/bower/lib/util/cmd.js:102:21)\n at ChildProcess.emit (events.js:400:28)\n at maybeClose (internal/child_process.js:1088:16)\n at Process.ChildProcess._handle.onexit (internal/child_process.js:296:5)" }]
环境版本
- Bower: v1.8.14
- Node: v14.21.1
排查步骤
- 直接在CI runner中测试Git仓库访问:在CI脚本中添加
git ls-remote --tags --heads https://github.com/l-lin/angular-datatables.git(替换为报错的仓库地址),查看具体错误信息(exit 128是通用码,直接执行能获取更细节的原因,比如认证失败、速率限制、网络超时) - 验证CI runner网络连通性:添加网络测试命令,比如
ping github.com -c 5或curl -v https://github.com,确认网络是否稳定、DNS解析是否正常 - 检查GitHub API速率限制:未认证的GitHub请求有配额限制,CI环境频繁拉取可能触发限制。在CI中执行
curl -I https://api.github.com/rate_limit查看剩余配额,可配置GitHub个人访问令牌(PAT)认证:
注意将git config --global url."https://${GITHUB_PAT}@github.com/".insteadOf https://github.com/${GITHUB_PAT}存入GitLab CI的环境变量中,避免硬编码 - 配置Bower依赖缓存:在GitLab CI配置中添加缓存规则,缓存
~/.bower和bower_components目录,减少重复请求:cache: paths: - ~/.bower - bower_components - 检查Git版本兼容性:执行
git --version确认CI runner的Git版本,旧版本Git可能与Bower存在兼容性问题,必要时升级Git - 临时替换仓库源:若特定仓库访问不稳定,可在
bower.json中将对应仓库替换为国内镜像源(如Gitee镜像),测试是否能正常安装
内容的提问来源于stack exchange,提问作者Tom
相关产品推荐
相关产品推荐

