How to control java version used by buildAgent?

Hi,

I've run into a build compilation problem that I cannot reproduce with command line:

An exception has occurred in the compiler (1.6.0_20)

I realized my cli java version:

java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Server VM (build 17.1-b03, mixed mode)



is different from the one used by my local agent ('java -version' run through a command line build)

java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.5) (6b20-1.9.5-0ubuntu1~9.10.1)
OpenJDK Server VM (build 19.0-b09, mixed mode)

I run buildAgent with the same root user (afaik) I tried the 'java -version' with.

How can they be different? I don't understand where the buildAgent find this version.

Thanks for your help.

Teamcity 6.0.1 on Ubuntu 9.04
4 comments
Comment actions Permalink

The first thing I would do is take a look at buildAgent/logs/teamcity-agent.log.  In my logs, the GenericProgramRunner will report the full command line used to run the build, which includes the full path to the java executable.  So you should be able to verify that it is using the version that you expect.

My believe is that the buildAgent is using JAVA_HOME to decide which version of java to launch, and if that variable hasn't been set, it will instead try to use the same version of java that was used to launch the agent itself.  We actually have a few build configurations that specify the JAVA_HOME environment variable in the build configuration, so you might need to double check that for additional surprises.


The script to start the agent itself seems to use JAVA_HOME by preference, and if that isn't set will find java on the path and set the environment variable for itself?


Disclaimer: most of my agents run on windows, so I can't promise that all of this will translate to Ubuntu.

0
Comment actions Permalink

Hi

Agent uses JRE/JDK specified by JAVA_HOME environment variable.
How is it configured?

Michael

0
Comment actions Permalink

Ok, found the problem, thanks for pointing me in the right direction.

FYI:

JAVA_HOME was properly set and used (/usr/lib/jvm/java-6-sun)

BUT I had these symlinks configured:

/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk/jre/bin/java



In my PATH, JAVA_HOME has the priority over /usr/bin, so it seems some builds and buildAgent itself is using directly /usr/bin/java instead of just java.

hence the mismatch afaiu

I'm a strong supporter of OpenSource unfortunately, I have really a lot of [JVM Crashed] (more than one a day for less than 20 builds), plus some recent unexpected compilation failure.
So I'll redirect /usr/bin/java to /usr/lib/jvm/java-6-sun/bin/java.
0
Comment actions Permalink

I'm still having problems with buildAgent.

It seem using its own version of the environment variables:

Using watcher: /opt/local/buildAgent/plugins/mavenPlugin/maven-watcher/maven-watcher-agent.jar
[11:41:12]: MAVEN_OPTS =  *A LOT OF STUFF*
[11:41:12]: M2_HOME = /opt/local/maven
[11:41:12]: PATH = /opt/local/maven/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[11:41:12]: JAVA_HOME = /usr


where if i myself logged as the same user echo the variables values I get:



PATH = /usr/lib/jvm/java-6-sun/bin:/opt/local/maven/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
JAVA_HOME = /usr/lib/jvm/java-6-sun
MAVEN_OPTS = -server -Xmx512m -XX:MaxPermSize=256m

Why isn't buildagent using the value I've set? Where can I control that?

cheers
0

Please sign in to leave a comment.