Jenkins Slave Environment Variable Refresh
Asked Answered
A

5

15

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?

Alkyne answered 15/12, 2011 at 16:56 Comment(0)
C
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.

Clouded answered 16/12, 2011 at 11:36 Comment(5)
Adding the path to the Node rather than the slave's environment did the trick, thanks.Alkyne
The question remains unanswered. I need my slave to somehow update the PATH variable "on the fly".Carburetor
@AlexOkrushko Did you find an automated way to update a slave's configuration specially for adding/updating an ENV variable?Elissa
@ArunSangal this was very long time ago, but I think I've done something similar as described in the answer below.Carburetor
@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).Elissa
D
13

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
Donavon answered 29/5, 2015 at 0:34 Comment(4)
thanks for pointing us to the bug report. Updating to >=1.617 fixes thisMatter
Isn't there a way to add/update ENV variables in slave's configuration using Jenkins Rest/API?Elissa
You do not need to fully delete the slave! Simply restarting the slave agent is enough.Stewardess
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).Dibasic
C
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.

Clouded answered 16/12, 2011 at 11:36 Comment(5)
Adding the path to the Node rather than the slave's environment did the trick, thanks.Alkyne
The question remains unanswered. I need my slave to somehow update the PATH variable "on the fly".Carburetor
@AlexOkrushko Did you find an automated way to update a slave's configuration specially for adding/updating an ENV variable?Elissa
@ArunSangal this was very long time ago, but I think I've done something similar as described in the answer below.Carburetor
@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).Elissa
R
2

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

Revolving answered 4/2, 2015 at 13:48 Comment(0)
F
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

Filling answered 27/2, 2019 at 20:13 Comment(0)
C
0

No restart required.

Manage Jenkins -> Manage Nodes and Clouds Click on the desired slave. Then choose "Disconnect" from the panel.

Slave will auto re-connect. If it doesn't, click on "Launch".

This will refresh environment variables including "PATH".

Chordate answered 1/12, 2021 at 10:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.