Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure a Hudson job to use a specific JDK?

Tags:

java

hudson

I have a number of projects running on a Hudson slave. I'd like one of them to run Ant under Java6, rather than the default (which is Java5 in my environment).

In the project configuration view, I was hoping to find either:

  • An explicit option allowing me to set a custom JDK location to use for this project.
  • A way to set custom environment variables for this project, which would allow me to set JAVA_HOME to the JDK6 location. The would make Ant pick up and run on Java6 as desired.

Is there a way to do either of the above? If one of those facilities is available, I can't see how to access it. I'm running on Hudson 1.285.

I would rather avoid using an "execute shell" operation instead of the "invoke Ant" operation if possible: my slave is on z/OS and Hudson doesn't seem to create the temporary shell scripts properly on this platform (probably an encoding issue).

like image 291
rewbs Avatar asked Apr 14 '09 14:04

rewbs


2 Answers

We have both Java 5 and Java 6 configured for use in our Hudson instance.

Under Manage Hudson -> Configuration System you can add a number of JDKs and specify the path for JAVA_HOME. In the configuration for each job you then selected which JDK you would like that job to run on.

like image 145
Mark Avatar answered Oct 04 '22 13:10

Mark


It turns out that if you make the build parametrised, any string parameters you add become environment variables. With this approach, it is possible to set any environment variable for the build, including JAVA_HOME, which is picked up by Ant.

So the best solution for me was:

  1. In the job configuration page Tick "This build is parameterized"
  2. Add an new String parameter called JAVA_HOME and with the default value set to the JDK location

It's not obvious that build string parameters become environment variables, but once you know that they do, it's easy to set the JDK this way.

The developers on the Hudson mailing list recommended another approach using the master JDK configurations and overrides in the node configurations... but just setting the JAVA_HOME env var seems way easier to me.

like image 41
rewbs Avatar answered Oct 04 '22 13:10

rewbs