在 Ubuntu 上用 Jenkins 部署慢,通常不是单一原因,而是若干常见因素叠加。下面按最常见 → 较少见的顺序说明,并给出排查方向。
这是第一嫌疑。
表现
Downloading原因
解决
# Maven
<mirror>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
# npm
npm config set registry https://registry.npmmirror.com
# pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
每次都重新拉代码、重新下载依赖。
问题点
建议
Workspace 持久化-v ~/.m2:/root/.m2
-v ~/.npm:/root/.npm
Jenkins 本身 + 构建进程吃资源。
常见瓶颈
检查
top
free -h
iostat -x 1
优化
checkout([
$class: 'GitSCM',
extensions: [[$class: 'CloneOption', depth: 1, shallow: true]]
])
建议
建议
优化示例
parallel {
stage('Test A') { ... }
stage('Test B') { ... }
}
Ubuntu 默认 systemd-resolved 有时很慢。
排查
time curl https://maven.aliyun.com
解决
/etc/resolv.conf
nameserver 223.5.5.5
df -h
df -i
会显著拖慢文件操作。
time 测耗时Ubuntu 上 Jenkins 部署慢,90% 是“依赖下载 + 无缓存 + 资源不足”三类问题。
如果你愿意,可以告诉我:
我可以直接帮你给出针对性优化方案。