在 Debian 上运行的 Jenkins 设置代理(Proxy),常见有 三种场景,下面分别说明:
适用于:Jenkins 访问互联网(插件下载、更新等)需要走 HTTP/HTTPS 代理
编辑:
sudo vim /var/lib/jenkins/hudson.model.UpdateCenter.xml
示例:
<hudson.model.UpdateCenter>
<proxy>
<name>proxy.example.com</name>
<port>8080</port>
<userName>user</userName>
<password>pass</password>
</proxy>
</hudson.model.UpdateCenter>
重启 Jenkins:
sudo systemctl restart jenkins
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 'curl https://example.com'
}
}
}
}
export http_proxy=http://proxy.example.com:8080
export https_proxy=http://proxy.example.com:8080
适用于:Agent 在隔离网络,需经代理连接 Jenkins Master
java -Dhttp.proxyHost=proxy.example.com \
-Dhttp.proxyPort=8080 \
-Dhttps.proxyHost=proxy.example.com \
-Dhttps.proxyPort=8080 \
-jar agent.jar -url http://jenkins.example.com
或使用 JAVA_OPTS:
export JAVA_OPTS="-Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=8080"
编辑:
sudo vim /etc/environment
添加:
http_proxy="http://proxy.example.com:8080"
https_proxy="http://proxy.example.com:8080"
no_proxy="localhost,127.0.0.1"
然后:
sudo systemctl daemon-reload
sudo systemctl restart jenkins
✅ 插件安装失败 → 检查 HTTP Proxy
✅ git clone 超时 → no_proxy 是否包含 git 服务器
✅ agent 无法连接 → agent JVM 代理参数是否正确
如果你能说明是 哪一种代理需求(Jenkins 上网 / 构建用 / Agent 连接),我可以给你更精确的配置示例。