公司爲了省錢,除了一臺服務器可以上網以外,其他的都是內網服務器,我把jenkins裝在內網服務器下,用Dockder來搭建的,因此就出現題目的問題。怎麼設置Docker jenkins容器下的maven http代理,讓mvn能下載包。
# 進入容器 docker exec -it jenkins bash # 查看Maven安裝配置 cat /var/jenkins_home/hudson.tasks.Maven.xml
<?xml version='1.1' encoding='UTF-8'?> <hudson.tasks.Maven_-DescriptorImpl> <installations> <hudson.tasks.Maven_-MavenInstallation> <name>maven3.5.2</name> <properties> <hudson.tools.InstallSourceProperty> <installers> <hudson.tasks.Maven_-MavenInstaller> <id>3.5.2</id> </hudson.tasks.Maven_-MavenInstaller> </installers> </hudson.tools.InstallSourceProperty> </properties> </hudson.tasks.Maven_-MavenInstallation> </installations> </hudson.tasks.Maven_-DescriptorImpl>
能夠看到咱們這裏用的是3.5.2版本
那麼的Maven所在的目錄在docker
/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven3.5.2
# 修改setting文件,若是有掛載,那直接在宿主機上修改便可,省得進來容器裏面,還要安裝vim vim /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven3.5.2/conf/settings.xml
在xml中的settings標籤下增長如下內容vim
<proxies> <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <host>代理服務器IP</host> <port>代理服務器端口</port> <!-- <username></username> <password></password> --> </proxy> </proxies>
docker restart jenkins #重啓完,打開jenkins,mvn命令能下載包了