Proxy

Jenkins 和 HTTPS:無法連接到伺服器

  • March 19, 2016

我們有一個位於https連接上的 Subversion 儲存庫。我可以在本地連接到它(不需要代理):

$ svn ls --username=qazwart --password=swordfish \
   https://svn.corpwad.com/repos/potzrebie/branches/build-test
build.xml
src
...

現在,我登錄到需要代理的建構伺服器:

$ ssh tomcat@jenkins.corpwad.net
Last login: Thu Aug 14 09:22:48 2014 from qazwart.corpwad.net
$ export | egrep "JENKINS|_proxy"
declare -x JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dhttps.proxyHost=proxy.corpwad.net -Dhttp.proxyHost=proxy.corpwad.net -Dhttp.proxyPort=3128 -Dhttps.proxyPort=3128 -Dhttp.auth.preference=Basic"
declare -x http_proxy="http://proxy.corpwad.net:3128"
declare -x https_proxy="http://proxy.corpwad.net:3128"

正如你所看到的,我已經JENKINS_JAVA_OPTOPNS為我的代理設置了,我已經https_proxy設置了。代理不需要登錄,儘管我們的 Subversion repo 需要:

讓我們試試wget

$ wget -O - --user=qazwart --password=swordfish https://svn.corpwad.com/repos/potzrebie/branches/build-test
--2014-08-14 09:54:09--  https://svn.corpwad.com/repos/potzrebie/branches/build-test
Resolving proxy.ilcb.tcprod.local... 10.80.12.90
Connecting to proxy.corpwad.net|10.80.12.90|:3128... connected.
Proxy request sent, awaiting response... 401 Authorization Required
Connecting to proxy.corpwad.net|10.80.12.90|:3128... connected.
Proxy request sent, awaiting response... 301 Moved Permanently
Location: https://svn.corpwad.com/repos/potzrebie/branches/build-test [following]
--2014-08-14 09:54:10--  https://svn.corpwad.com/repos/potzrebie/branches/build-test
Connecting to proxy.ilcb.tcprod.local|10.80.12.90|:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 1130 (1.1K) [text/html]
Saving to: “STDOUT”

0% [                                                                               ] 0            --.-K/s              <html><head><title> potzrebie - Revision 1937: /branches/build-test</title></head>
<body>
<h2> potzrebie - Revision 1937: /branches/build-test</h2>
<ul>
 <li><a href="../">..</a></li>
 <li><a href="build.xml">build.xml</a></li>
 ...
</ul>
100%[==============================================================================>] 1,130       --.-K/s   in 0s      

2014-08-14 09:54:10 (51.6 MB/s) - written to stdout [1130/1130]
$

好的,我可以通過wget連接到我的儲存庫。這意味著我確實有從我們的建構伺服器到我們的儲存庫的網路連接。不幸的是,我的系統沒有用於測試的 Subversion 命令行客戶端。我將不得不請我們的 IT 部門為其安裝 RPM,但現在,我無法對其進行測試。幸運的是,Jenkins 不需要命令行客戶端,因為它使用svnkit。:我創建了一個 Jenkins Freestyle 作業,選擇Subversion作為我的儲存庫,在Repository URL欄位中,我將放置https://svn.corpwad.com/repos/potzrebie/branches/build-test. 我用使用者名和密碼設置了一個全域憑證。然而,當仍在我們的建構配置螢幕上時,我得到了這個:qazwart``swordfish

Unable to access https://svn.corpwar.com/repos/potzrebie/branches/build-test : svn: E175002: OPTIONS /repos/potzrebie/branches/build-test failed 
org.tmatesoft.svn.core.SVNException: svn: E175002: OPTIONS /repos/potzrebie/branches/build-test failed
   at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:388)
   at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:373)
   at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:361)
   at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.performHttpRequest(DAVConnection.java:707)
....
Caused by: svn: E175002: OPTIONS /repos/potzrebie/branches/build-test failed
       at org.tmatesoft.svn.core.SVNErrorMessage.create(SVNErrorMessage.java:208)
       at org.tmatesoft.svn.core.SVNErrorMessage.create(SVNErrorMessage.java:154)
       at org.tmatesoft.svn.core.SVNErrorMessage.create(SVNErrorMessage.java:97)
       ... 88 more
Caused by: org.tmatesoft.svn.core.SVNException: svn: E175002: OPTIONS request failed on '/repos/potzrebie/branches/build-test'
svn: E175002: connection refused by the server
       at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:64)
       at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:51)
       at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection._request(HTTPConnection.java:777)
       at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:382)
       ... 87 more
Caused by: svn: E175002: OPTIONS request failed on '/repos/potzrebie/branches/build-test'
       at org.tmatesoft.svn.core.SVNErrorMessage.create(SVNErrorMessage.java:208)
       at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection._request(HTTPConnection.java:775)
       ... 88 more
Caused by: svn: E175002: connection refused by the server
       at org.tmatesoft.svn.core.SVNErrorMessage.create(SVNErrorMessage.java:208)
       at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection._request(HTTPConnection.java:520)
       ... 88 more
Caused by: java.net.ConnectException: Connection refused
       at java.net.PlainSocketImpl.socketConnect(Native Method)

我有一種感覺,我錯過了一個小步驟,但我無法弄清楚。

發現問題。雖然我正在設置JENKINS_JAVA_OPTIONS,但 Tomcat 本身啟動時並沒有設置。我進入$CATALINA_BASE/bin/setenv.sh並補充說:

CATALINA_OPTS="$CATALINA_OPTS $JENKINS_JAVA_OPTIONS -DJENKINS_HOME=...

這會在 Java 啟動時設置所需的屬性。

我找到了一種將這些值導入 Java 的替代方法,該方法在 Windows 上下文中對我有用。

在下面C:\Program Files (x86)\Jenkins\jenkins.xml

我編輯了從

<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>

<arguments>-Xrs -Xmx256m -Djava.awt.headless=true -Dhttp.proxyHost=proxy.myproxy.com Dhttp.proxyPort=99999 -Dhttp.auth.preference=Basic -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>

關鍵插入是**-Dhttp.proxyHost=proxy.myproxy.com Dhttp.proxyPort=99999 -Dhttp.auth.preference=Basic**

Jenkins.xml 文件

Jenkins.xml 文件本身讓我去搜尋這個jre\bin\java執行檔可能在哪裡,所以我可能會探查它以更好地理解它的命令行參數的作用。C:\Program Files (x86)\Java\jre6\bin>java正如我在具有表單的參數下發現的那樣,-D<name>=<value>是我需要設置的參數係列,以使代理設置正確地傳達給 Java。 java命令行參數

我非常努力地試圖讓我的 SVN 設置在代理伺服器後面工作,這非常令人困惑,因為 Jenkins 本身可以連接到代理,正如我為其啟用的代理設置所告訴的那樣,它通過了測試。這是非常不直覺的,除此之外還需要進一步的設置來建立代理設置。 JenkinsProxyConnectionSuccess

只是為了幫助其他人偶然發現這個問題,我最初遇到的錯誤是:

Checking out a fresh workspace because there's no workspace at C:\SVNXXX\JenkinsWorkspace
Cleaning local Directory .
Checking out http://xxxxxxxxxx/trunk at revision '2016-03-18T16:12:17.711 -0700'
ERROR: Failed to check out http://xxxxxxxxxxxx/trunk
org.tmatesoft.svn.core.SVNException: svn: E175002: connection refused by the server
svn: E175002: OPTIONS request failed on 'xxxxxxxxx/trunk'

引用自:https://serverfault.com/questions/620459