14

I have a Jenkins Slave (A Windows PC) which has the JAVA_HOME environment variable. I updated the Java version on the Slave so I also updated the Environment Variable.

When I look at the system properties of this Slave via Jenkins web interface the JAVA_HOME property is reported as the old one.

Running echo %PATH% on the Windows PC shows the correct values. Running println System.getenv("PATH") on the Jenkins Node script console for the Slave shows the old JAVA_HOME value.

I have tried to delete and add the Slave again and restarted Jenkins server. Still the old value is not updated.

Any thoughts?

Akhil Jain
  • 12,808
  • 13
  • 51
  • 88
C0deAttack
  • 23,507
  • 18
  • 68
  • 79

4 Answers4

11

This is a bug in Jenkins: https://issues.jenkins-ci.org/browse/JENKINS-27739

3 ways to solve (I have personally confirmed each):

  1. Update Jenkins to >=1.617 (Recommended)
  2. Restart Jenkins master
  3. Delete Jenkins slave, then re-add it
kmiles
  • 162
  • 1
  • 6
  • 1
    thanks for pointing us to the bug report. Updating to >=1.617 fixes this – pHiL Jul 02 '15 at 11:29
  • Isn't there a way to add/update ENV variables in slave's configuration using Jenkins Rest/API? – AKS Dec 09 '15 at 16:32
  • 2
    You do not need to fully delete the slave! Simply restarting the slave agent is enough. – Johan Bjäreholt Jun 28 '16 at 08:18
  • Agreed with @JohnBjareholt, it is clear that the server is caching the environment established by the slave even when the environment is loaded by the slave's startup script on the remote machine (no changes to the server configuration for the slave). Restarting the slave didn't resolve this issue for me. Interestingly enough, a server restart reloads these environment settings (even those declared in a slave's startup script). – dan Oct 04 '16 at 18:43
9

Hudson/Jenkins does not use the slave environment variables as it supports multiple java versions so you configure the java home environment variables in the GUI.

What you need to do is go to Manage Hudson/Jenkins then choose Manage Nodes. Choose the Node you want to configure from the list and then choose Configure. Down the bottom there's a Node Properties section. Check the Tool Locations checkbox. Click on Add then Select your JDK in the dropdown list and add the new path to it.

Robert Longson
  • 102,136
  • 21
  • 218
  • 211
  • Adding the path to the Node rather than the slave's environment did the trick, thanks. – C0deAttack Dec 20 '11 at 11:41
  • 8
    The question remains unanswered. I need my slave to somehow update the PATH variable "on the fly". – Alex Okrushko Sep 06 '12 at 19:51
  • @AlexOkrushko Did you find an automated way to update a slave's configuration specially for adding/updating an ENV variable? – AKS Dec 09 '15 at 16:33
  • @ArunSangal this was very long time ago, but I think I've done something similar as described in the answer below. – Alex Okrushko Dec 14 '15 at 16:30
  • @AlexOkrushko - With Jenkins REST/API it's possible, I got some success, I'll share what I found. In my case, I'm creating the slave using Ansible + Jenkins Swarm Plugin (way but it doesn't create ENV variables). I'm planning to create the slave using the first part and then call a second Jenkins job (which will configure the newly created slave to embedd/add/update any ENV variables). – AKS Dec 14 '15 at 17:12
2

Restart the slave, this fixed the issue on my configuration.

1

You can update your Jenkins version, it will solve it. Otherwise this worked for me (Jenkins 1.6, build/test node: MacOSX Mojave):

First install java 8 in your build/test node using the commands:

brew update
brew cask install caskroom/versions/java8

Then in Jenkins web panel click on your build/test node, then click on Configure and then click in the Advanced... button, this will show you multiple text fields. Then in the JavaPath field add the path to your java 8.

enter image description here

For me this path is like:

/Library/Java/JavaVirtualMachines/jdk1.8.X_XXX.jdk/Contents/Home/bin/java

Note: remember replace X_XXX with your java 8 version before.

Then Save.

After that disconnect the build/test node and connect it again. This should solve the problem.

Source

Pedro Trujillo
  • 916
  • 12
  • 13