[Gitlab CI] jq: command not found

前置

查阅构建记录,问题出在 jq 包未找到

1
2
3
/bin/bash: line 192: jq: command not found
Cleaning up project directory and file based variables00:00
ERROR: Job failed: exit code 1

然而脚本里已经有相应的安装逻辑,且位于 before_script,确保每个 job 都会安装。

定位

继续检查日志,有

1
2
3
4
5
Reading package lists...

E: The repository '[http://deb.debian.org/debian](http://deb.debian.org/debian) buster Release' does not have a Release file.
E: The repository '[http://deb.debian.org/debian-security](http://deb.debian.org/debian-security) buster/updates Release' does not have a Release file.
E: The repository '[http://deb.debian.org/debian](http://deb.debian.org/debian) buster-updates Release' does not have a Release file.

显然,jq 包是没有装上的。考虑到所用镜像版本较老 (Node 16),其基于 Debian Buster (Debian 10),但这个版本的 Debian 已经到了支持生命周期的末期,官方软件源已经被移动到归档库中,导致原来的软件源地址返回 404 错误。

解决方案

使用 Debian Buster 归档源

1
2
3
4
5
6
7
8
9
# before_script:
# - apt-get update && apt-get upgrade -y && apt-get install -y curl jq unzip

# 改为
before_script:
- echo 'deb http://archive.debian.org/debian buster main' > /etc/apt/sources.list
- echo 'deb http://archive.debian.org/debian-security buster/updates main' >> /etc/apt/sources.list
- apt-get -o Acquire::Check-Valid-Until=false update # 强制屏蔽时间戳
- apt-get install -y curl jq unzip

再次构建,成功。

总结

这个问题 StackOverflow 上没有很好的解决方案,感谢 Claude 3.7 大人。最后,采用 Node 16 是当初为了跑通 Hexo 的各种魔改插件而做出的妥协,今日的解决方案终究不是治标之策。换用更现代化的博客框架,或许该提上日程。