免费开源的玩意儿就是折腾人啊。本来Jenkins+Testlink已经成功集成了,但是Team的服务器资源做了调整,原本在同一局域网中的Jenkins和Testlink,前者部署在域内(因为项目环境在域内),而Testlink部署在域外(以保证外派到客户那里的测试人员也能访问这一测试管理平台)。这种调整的直接影响是,之前的自动化测试代码没办法在Jenkins上集成管理。因为部署Jenkins的机器(域内)如果要访问Testlink,必须要设置代理。而Jenkins Testlink Plugin不会读取浏览器的代理设置,而我在Jenkins配置页面也没有找到代理相关的配置。
Jenkins控制台输出如下:
FATAL: Error verifying developer key: Failed to read server's response: Connection timed out: connect br.eti.kinoshita.testlinkjavaapi.TestLinkAPIException: Error verifying developer key: Failed to read server's response: Connection timed out: connect at br.eti.kinoshita.testlinkjavaapi.MiscService.checkDevKey(MiscService.java:71) at br.eti.kinoshita.testlinkjavaapi.TestLinkAPI.<init>(TestLinkAPI.java:150) at hudson.plugins.testlink.TestLinkHandler.<init>(TestLinkHandler.java:99) at hudson.plugins.testlink.TestLinkBuilder.createTestLinkHandler(TestLinkBuilder.java:320) at hudson.plugins.testlink.TestLinkBuilder.perform(TestLinkBuilder.java:139) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19) at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:682) at hudson.model.Build$RunnerImpl.build(Build.java:177) at hudson.model.Build$RunnerImpl.doRun(Build.java:139) at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:448) at hudson.model.Run.run(Run.java:1376) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:175) Caused by: org.apache.xmlrpc.XmlRpcException: Failed to read server's response: Connection timed out: connect at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:161) at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143) at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69) at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56) at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167) at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158) at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147) at br.eti.kinoshita.testlinkjavaapi.BaseService.executeXmlRpcCall(BaseService.java:90) at br.eti.kinoshita.testlinkjavaapi.MiscService.checkDevKey(MiscService.java:65) ... 13 more Caused by: java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.<init>(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.http.HttpClient.New(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source) at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.writeRequest(XmlRpcSunHttpTransport.java:104) at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:151) ... 21 more
仔细想想Jenkins集成Testlink的原理,其实就是Jenkins创建IXR_Client对象,调用Testlink的xmlrpc接口。既然报“Failed to read server's response”,就是无法连接xmlrpc接口。我用Zend Studio对testlink源码进行调试,错误出现在class-IXR.php的fsockopen方法中。if ($this->timeout) {
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
} else {
$fp = @fsockopen($this->server, $this->port, $errno, $errstr);
}所以说,用域内的机器通过浏览器代理,访问testlink(域外)平台,是没有问题的;但是调用testlink的xmlrpc接口,恐怕要调整这部分的代码。