在 Debian 上运行的 Jenkins 配置代理,常见有 3 种场景。下面按使用频率从高到低说明。
适用于:
Manage Jenkins → Plugins / System
Manage Jenkins → System
proxy.example.com8080localhost,127.0.0.1,.example.com
编辑:
sudo nano /etc/default/jenkins
添加 JVM 参数:
JAVA_ARGS="-Dhttp.proxyHost=proxy.example.com \
-Dhttp.proxyPort=8080 \
-Dhttps.proxyHost=proxy.example.com \
-Dhttps.proxyPort=8080 \
-Dhttp.nonProxyHosts=localhost|127.0.0.1|.example.com"
重启 Jenkins:
sudo systemctl restart jenkins
✅ 适合 Debian + systemd 环境
适用于:
pipeline {
agent any
environment {
HTTP_PROXY = "http://proxy.example.com:8080"
HTTPS_PROXY = "http://proxy.example.com:8080"
NO_PROXY = "localhost,127.0.0.1"
}
stages {
stage('Build') {
steps {
sh 'npm install'
}
}
}
}
在:
Manage Jenkins → Nodes
编辑节点 → Node Properties → Environment variables
适用于:
server {
listen 80;
server_name jenkins.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Jenkins 设置:
Manage Jenkins → System → Jenkins URL
改为:
https://jenkins.example.com/
✅ 插件无法下载
→ 检查 HTTP Proxy 是否配置正确
✅ Agent 连不上 Master
→ 检查 NO_PROXY / 防火墙
✅ Docker 构建失败
→ Docker daemon 也要配代理:
sudo mkdir -p /etc/systemd/system/docker.service.d
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080"
如果你能说明是 哪种代理(出网 / Agent / 反向代理),我可以给你更精确的配置。