0
  • Environment - Linux. << I log on to this machine as me (c123456) and then do "sudo su - jenkins"
  • Language - Java
  • Project Structure
    src/java -- Java source code

    test/java -- Junit Unit tests

    src/java-test -- Integration tests

  • Build system - Gradle

build.gradle sourceSets definitions:

sourceSets {
   main {
      java {
         srcDir 'src/java'
      }
   }
   test {
      java {
         srcDir 'test/java'
      }
   }
   integrationTest {
      java {
         srcDir 'src/java-test'
      }
   }
}
  • Lets say I successfully checked out source code for Project "ProjectABC" somewhere.
  • When I run "gradle clean build", everything runs fine on my local machine (Windows Win7 desktop) using Cygwin session. Java compile and test run is successful.

  • When I run "gradle clean build" on a Linux terminal i.e. using a putty Session, it fails during the test task but Java compile part is successful.

  • When I run "gralde clean build -x test", it works (as we are excluding test task call).

Im getting the following error message when I use "gradle clean build" on a putty session:

:compileTestJava
Download http://artifactory_server2:8081/artifactory/libs-thirdparty-local/junit/junit/4.11/junit-4.11.pom
Download http://artifactory_server2:8081/artifactory/libs-thirdparty-local/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.pom
Download http://artifactory_server2:8081/artifactory/libs-thirdparty-local/junit/junit/4.11/junit-4.11.jar
Download http://artifactory_server2:8081/artifactory/libs-thirdparty-local/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
/production/jenkinsAKS/jobs/ProjectABCUtilities/workspace/test/java/com/tr/ids/util/test/tree/TestMultiParentTree.java:5: warning: unmappable character for encoding UTF8
 * Copyright � 2005 Thomson MICROMEDEX.  All Rights Reserved.
             ^
/production/jenkinsAKS/jobs/ProjectABCUtilities/workspace/test/java/com/tr/ids/util/test/tree/TestSingleParentTree.java:5: warning: unmappable character for encoding UTF8
 * Copyright � 2005 Thomson MICROMEDEX.  All Rights Reserved.
             ^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processTestResources UP-TO-DATE
:testClasses
:test
Download http://artifactory_server2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.pom
Download http://artifactory_server2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.build/0.6.2.201302030002/org.jacoco.build-0.6.2.201302030002.pom
Download http://artifactory_server2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.jar
Xlib: connection to "localhost:12.0" refused by server
Xlib: PuTTY X11 proxy: wrong authorisation protocol attempted

com.tr.ids.util.test.chart.TestChartUtilities > getPieChart FAILED
    java.lang.InternalError at TestChartUtilities.java:89

com.tr.ids.util.test.chart.TestChartUtilities > getLegend FAILED
    java.lang.NoClassDefFoundError at TestChartUtilities.java:103

com.tr.ids.util.test.chart.TestChartUtilities > useString FAILED
    java.lang.NoClassDefFoundError at TestChartUtilities.java:143

140 tests completed, 3 failed
:test FAILED

FAILURE: Build failed with an exception.

As you see above, ":test" task is called at the very last. Only this project ProjectABC has this test case where the test source code has a .java file which includes the following code:

i.e. under /test/java/com/tr/ids/util/test/...*.java, *.html

The file which is giving problem is: TestChartUtilities.java

Test source code - Java file Code snapshot is:. See lines/line# 89, 103 and 143 where line contains: "result = ChartUtil." keyword

package com.tr.ids.util.test.chart;

import java.awt.Color;
import java.io.UnsupportedEncodingException;

import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

import com.tr.ids.util.api.chart.ChartData;
import com.tr.ids.util.api.chart.ChartUtil;
import com.tr.ids.util.test.BaseTestCase;

..
....
......more code here ...
....
...

// #############################################################################
// Test.
// #############################################################################
/**
 * Test simple string with ampersand character.
 */
   public void getPieChart() {
      ChartData chartData = new ChartData();
      try {
         chartData.addChartItem(25, new Color(255,255,0));
         chartData.addChartItem(25, new Color(255,0,255));
         chartData.addChartItem(25, new Color(0,255,255));
      }
      catch (Exception e) {
         fail("Exception occured while building the ChartData object (probably 0 amount)");
      }
      byte[] result = null;
      try {
         result = ChartUtil.drawPieChart(chartData, 300);          // <--- line# 89 which is failing.
      } catch (Exception e) {
         fail("Exception occured trying to drawPieChart.");
      }
      assertNotNull("No pie chart returned", result);

   }

..
....
......more code here ...
....
...

/**
 * Test simple string with apostrophe and quote characters.
 */
   public void getLegend() {
      byte[] result = null;
      try {
         result = ChartUtil.drawLegend("ff0000", 40);          // <--- line# 103
      } catch (Exception e) {
         fail("Exception occured while drawing a legend box");
      }
      assertNotNull("No legend image returned", result);
   }

/**
 * Test simple string with less than and greater than characters.
 */
   public void useString() {
      ChartData chartData = new ChartData();
      try {
         chartData.addChartItem(25, new Color(255,255,0));
         chartData.addChartItem(25, new Color(255,0,255));
         chartData.addChartItem(25, new Color(0,255,255));
      }
      catch (Exception e) {
         fail("Exception occured while building the ChartData object (probably 0 amount)");
      }

      String graphDesc = null;
      try {
         graphDesc = chartData.generateStringRepresentaion(false);
      } catch (UnsupportedEncodingException e1) {
         fail("Exception occured while building the ChartData object (probably 0 amount)");
      }

      ChartData chartData2 = new ChartData();
      try {
         chartData2.loadFromString(graphDesc);
      } catch (NumberFormatException e) {
         fail("NumberFormatException thrown loading from string");
      } catch (Exception e) {
         e.printStackTrace();
         fail("Exception thrown");
      }

      byte[] result = null;
      try {
         result = ChartUtil.drawPieChart(chartData2, 300);      // <--- line# 143
      } catch (Exception e) {
         fail("Exception occured trying to drawPieChart.");
      }
      assertNotNull("No pie chart returned for chart loaded from string", result);
   }

Now, As I mentioned earlier, in Cygwin (Windows local machine), everything works as I may have all the Graphical/AWT settings/tools available on my local machine via Cygwin.

Now, what could I be missing???

As I also getting the same error (when running via Putty session) in Jenkins job as well, I thought installing / using Jenkins "Xvfb Plugin" would help as it says:

Lets you control Xvfb virtual frame buffer X11 server with each build. It starts Xvfb before the build starts, and stops it with the build. This is very useful if your build requires X11 access, for instance runs tests that require GUI.

I configured this plugin according to the instructions: https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin

but, it's still giving me an error.

Jenkins logs (When I'm not using Jenkins Xvfb plugin) is showing the same error like I'm getting in a Putty session.

Similarly, when "gradle clean build -x test" is called, Jenkins job is successful but I have to run "gradle clean build" (which fails).

Now, When enabling Jenkins "Xvfb" plugin in Jenkins Global configuration (under Manager Jenkins > Configure System) and at Job's configuration level, I'm getting the following error in Jenkins log during the execution:

..
....
15:30:11 Xvfb starting$ Xvfb :2 -screen 0 1024x768x24 -fbdir /production/jenkinsAKS/2013-08-23_15-30-072456509552045645846xvfb
..
...
...
:compileTestJava
Download http://artifactory_server2:8081/artifactory/libs-thirdparty-local/junit/junit/4.11/junit-4.11.pom
Download http://artifactory_server2:8081/artifactory/libs-thirdparty-local/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.pom
Download http://artifactory_server2:8081/artifactory/libs-thirdparty-local/junit/junit/4.11/junit-4.11.jar
Download http://artifactory_server2:8081/artifactory/libs-thirdparty-local/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
/production/jenkinsAKS/jobs/ProjectABCUtilities/workspace/test/java/com/tr/ids/util/test/tree/TestMultiParentTree.java:5: warning: unmappable character for encoding UTF8
* Copyright � 2005 Thomson MICROMEDEX.  All Rights Reserved.
                 ^
/production/jenkinsAKS/jobs/ProjectABCUtilities/workspace/test/java/com/tr/ids/util/test/tree/TestSingleParentTree.java:5: warning: unmappable character for encoding UTF8
* Copyright � 2005 Thomson MICROMEDEX.  All Rights Reserved.
                 ^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processTestResources UP-TO-DATE
:testClasses
:test
Download http://artifactory_server2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.pom
Download http://artifactory_server2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.build/0.6.2.201302030002/org.jacoco.build-0.6.2.201302030002.pom
Download http://artifactory_server2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.jar
15:30:51 Xlib: connection to "localhost:16.0" refused by server
15:30:51 Xlib: PuTTY X11 proxy: wrong authorisation protocol attempted
15:30:52 
com.tr.ids.util.test.chart.TestChartUtilities > getPieChart FAILED
java.lang.InternalError at TestChartUtilities.java:89

com.tr.ids.util.test.chart.TestChartUtilities > getLegend FAILED
java.lang.NoClassDefFoundError at TestChartUtilities.java:103

com.tr.ids.util.test.chart.TestChartUtilities > useString FAILED
java.lang.NoClassDefFoundError at TestChartUtilities.java:143

140 tests completed, 3 failed
:test FAILED

FAILURE: Build failed with an exception.

As you notice, this time I'm getting lines.

15:30:51 Xlib: connection to "localhost:16.0" refused by server
15:30:51 Xlib: PuTTY X11 proxy: wrong authorisation protocol attempted
15:30:52 

When at Job level configuration for Xvfb's Advance configurtion, I mentioned value in the box for "Xvfb specific Display name" as 13 or 16 (as per the plugin), I see the same errors for tests part (as I got earlier), but X11 related error this time, comes as:

15:31:42 Xvfb starting$ Xvfb :16 -screen 0 1024x768x24 -fbdir /production/jenkinsAKS/2013-08-23_15-31-388454769980302593302xvfb
15:31:42 _XSERVTransSocketINETCreateListener: ...SocketCreateListener() failed
15:31:42 _XSERVTransMakeAllCOTSServerListeners: server already running
15:31:42 
15:31:42 Fatal server error:
15:31:42 Cannot establish any listening sockets - Make sure an X server isn't already running
15:31:42 unlink: No such file or directory
15:31:42 unlink  failed, errno 2
15:31:44 ERROR: Xvfb failed to start, consult the lines above for errors

ps -eAf|grep -i xvfb - doesn't show anything running on the Linux server.

When Jenkins job runs using Xvfb plugin, it initiates the call to start / stop the X Display during it's execution automatically (as per Xvfb plugin's features on Jenkins Xvfb help page).

I also found that X11 forwarding is enabled on Linux machine:

# grep X11F /etc/ssh/sshd_config
X11Forwarding yes                          
#

One thing I notice is, the user which I use to run Jenkins is: "jenkins" and once I log to the Linux machine as me (c123456 id) and then do "sudo su - jenkins", then, there's is NO .XAuthority file.

Doing: ... does show it exists: ls -ltra ~c123456

-rw------- 1 c123456 devgroup   406 Aug 23 13:07 .Xauthority

But, the same doesn't exist for user jenkins i.e. ls -ltra ~jenkins (doesn't have any .XAuthority file).

Linux $DISPLAY variable is set but "xclock" doesn't work. I have it X11 setting enabled/checked for X11 forwarding (at client side i.e. on my Windows local machine putty setting for target Linux machine session).

[c1234563@devserver1 ~]$ echo $DISPLAY localhost:15.0 [c1234563@devserver1 ~]$ xclock X connection to localhost:15.0 broken (explicit kill or server shutdown). [c1234563@devserver1 ~]$

I tried this link but still not able to resolve the issue, following what it says to resolve it.

http://froebe.net/blog/2008/11/14/getting-xlib-putty-x11-proxy-wrong-authentication-protocol-attempted-i-have-the-answer/

What could I be missing at this point which can help me:

1) to resolve the tests fail issue using Putty session or through Jenkins job way.

2) I'm wondering if Xvfb plugin is doing the X Display using memory frame buffers, then I should not install any X Display server/client on my local Windows machine / target Linux machine like XMing, XVnc/TightVnc etc.

4

2 回答 2

0

Putty 会话和 jenkins 作业可能会有 2 个稍微不同的运行环境。由于它的配置方式,Putty 想使用你的远程 X 服务器,而 jenkins 可能是无头的,需要 xfvb 或类似的环境。

为了使您的暂定槽 Putty 正常工作,您可能需要在服务器上添加 " ForwardX11Trusted yes" in /etc/ssh/sshd_config,或使用 xauth。但这会使您的 GUI 出现在您的 Windows 客户端上。可能不是您真正想要的:您不希望必须将显示导出到远程服务器来运行您的自动构建。

要修复詹金斯,我还不是 100% 确定。Xfvb 插件失败是因为您已经在它尝试使用的端口上运行了一个服务器。您可能需要检查 netstat -ln 并搜索端口(可能在 6000+ 左右)。让我们从那个开始。

于 2013-08-23T22:54:59.593 回答
0

这是一个奇怪的答案,但我做了以下事情来解决这个问题。我知道我迟早会需要 Xvfb 插件,但是..

  1. 删除了我的工作区/jenkins 工作 - 或重命名了 jenkins 工作。如果删除,请备份。
  2. 在腻子上, gradle clean build 和 gradle clean build jacocoTestReport 工作。
  3. 在詹金斯它仍然失败。一个。删除了 Jenkins Xvfb 插件 b。重启 Jenkins 实例
  4. 问题已解决。

正如我所说,对于 GUI 测试,我需要 Xvfb,但在完成上述步骤后,我遇到的问题现在不会出现。

最终更新:解决方案是删除 Jenkins 作业的工作区文件夹的数据。

于 2013-08-27T17:30:47.890 回答