在 Debian 上让 Jenkins 通过代理(Proxy)访问外网(如下载插件、更新源等),常见有几种场景。下面按最常见需求给你说明。
适用于:
proxy.company.com8080localhost,127.0.0.1,.internal✅ 适用于插件下载、更新中心
编辑 Jenkins 启动配置(Debian):
sudo nano /etc/default/jenkins
添加 JVM 参数:
JAVA_ARGS="-Dhttp.proxyHost=proxy.company.com \
-Dhttp.proxyPort=8080 \
-Dhttps.proxyHost=proxy.company.com \
-Dhttps.proxyPort=8080 \
-Dhttp.nonProxyHosts=localhost|127.0.0.1|.internal"
重启:
sudo systemctl restart jenkins
如果你是想 用 Nginx / Apache 代理 Jenkins(对外暴露)
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 配置:
http://jenkins.example.com/pipeline {
agent any
environment {
HTTP_PROXY = "http://proxy:8080"
HTTPS_PROXY = "http://proxy:8080"
}
stages {
stage('Build') {
steps {
sh 'mvn clean package'
}
}
}
}
git config --global http.proxy http://proxy:8080
curl -I https://updates.jenkins.io
-Dhttp.proxyUser=xxx -Dhttp.proxyPassword=xxx
你可以告诉我:
我可以直接给你对应完整配置示例。