Jenkins 的加速可以从启动速度、构建速度、流水线执行效率、资源利用等多个维度入手。下面按常见场景给你一套实用优化清单,从“立竿见影”到“进阶优化”都有。
jenkins-plugin-manager 精确控制插件# 查看插件依赖
Manage Jenkins → Plugins → Installed
JAVA_OPTS="-Xms512m -Xmx1024m -XX:+UseG1GC"
推荐:
mvn clean package -DskipTests \
-Dmaven.repo.local=/opt/maven-repo
或使用:
npm ci --cache ~/.npm --prefer-offline
DOCKER_BUILDKIT=1 docker build .
Declarative Pipeline
stage('Build') {
parallel {
stage('Service A') {
steps { sh 'make build-a' }
}
stage('Service B') {
steps { sh 'make build-b' }
}
}
}
多模块、多服务必用
archiveArtifactsstash / unstash 替代文件拷贝agent nonepipeline {
agent none
stages {
stage('Build') {
agent { label 'build' }
}
}
}
避免每个 stage 都启动 agent
checkout scm
skipDefaultCheckout()milestone + lock避免重复构建排队:
milestone()
lock('deploy-lock') {
// deploy
}
agent { label 'linux-build' }
agent {
docker {
image 'maven:3.9'
}
}
properties([
disableConcurrentBuilds()
])
防止资源争抢
docker system prune -f
| 插件 | 作用 |
|---|---|
| Pipeline | |
| Blue Ocean | UI 更快 |
| Job DSL | 减少 UI 操作 |
| Build Timeout | 防止卡死 |
| Throttle Concurrent Builds | 控制并发 |
| 优化项 | 效果 |
|---|---|
| 并行构建 | ⬆ 30–60% |
| 缓存依赖 | ⬆ 40–70% |
| 减少插件 | 启动快 50% |
| Docker layer 缓存 | 构建快 2–5 倍 |
你可以直接告诉我:
我可以给你针对你环境的 Jenkinsfile 优化方案。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。