1

I just setup a new jenkins slave which is running Windows server 2012. I already installed jdk-8u221-windows-x64 and set Java_home, Path like below

C:\Users\Administrator>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.8.0_221\

C:\Users\Administrator>echo %PATH%
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\
Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\
Program Files\Amazon\cfn-bootstrap\;C:\Program Files\Git\cmd;C:\Program Files\Ja
va\jdk1.8.0_221\\bin;C:\maven\bin;C:\maven\bin

However,build job running in this slave always complain that:

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK

Any idea of what might be causing this?

Update Sep 11th, 2019

I configure the slave node as method 2 of Technext's suggestion enter image description here

In a Job build configuration, I selected (System) in JDK option. If I choose JDK 8 update 221, this build job run successfully, but I want to use a (System) JDK which will get from environment variable in this node, so I can switch to another slave node without changing the JDK option. enter image description here

However, when I remote to this server, and open command prompt, move on to workspace folder of this project, let say: C:\jenkins_slave\workspace\project01\, then type the command: mvn clean install, it run without complain about jdk or jre as run from Jenkins.

Tien Dung Tran
  • 1,127
  • 4
  • 16
  • 32

1 Answers1

2

You may use any of these methods depending on what suits you:


Method 1)

Please configure your Windows' Node to point it to the JDK you want to use by following these steps:

  1. Go to Manage Jenkins > Global Tool Configuration > JDK > Add JDK

    Since you already have Java installed, uncheck the box Install automatically

    In Name section, just provide some meaningful identifier, not necessarily JAVA_HOME. Now in the JAVA_HOME text box, you can provide any value that you wish because you are anyways going to use a different value for your Windows node.

enter image description here

  1. Now go to Manage Jenkins > Manage Nodes > (Go to Configure section of your Windows node) > Node Properties

    Now enable the check-box that says Tool Locations. Click Add > From the drop-down, select the name you provided to your JDK in Global Tool Configuration section

    Now here you have to provide the JAVA_HOME path for your Windows node. So wherever it is, just mention that path in the Home text box as shown below:

enter image description here


Method 2)

Go to Manage Jenkins > Manage Nodes > (Go to Configure section of your Windows node) > Node Properties

Now enable the check-box that says Environment variables > Add

  • In Name text box, write Path (not PATH)
  • In Value text box, write the path of your JDK installation till bin as shown below.

enter image description here

In your case, add the following: C:\Program Files\Java\jdk1.8.0_221\bin;C:\Windows\System32;C:\maven-3.6.1\bin;%PATH%

I was not having Maven set in PATH so i added it to Node's configuration as shown above.

Note: In the Value text box, use semi-colon (;) as separator not comma (,)

Job's JDK config:

enter image description here

Job's command:

enter image description here

Job's output:

enter image description here


Method 3)

In your Windows Node's configuration, enable Environment variables and add below variable with the relevant value

Name: java.home

Value: C:\Program Files\Java\jdk1.8.0_221\jre

Note: It's java.home (all in small letters as shown below)

enter image description here

JAVA_HOME needs to point to a JDK installation (maven needs the tools.jar) but Maven actually uses the JRE within the JDK to run itself.

When using mvn -version, Maven uses Java's internal java.home property. This property is not the same thing as JAVA_HOME environment setting so it might fool you. It is actually a dynamic property showing you which JRE is running your code.

Ref: Java_home in Maven

Technext
  • 7,887
  • 9
  • 48
  • 76
  • Actually, I don't want to fix the JAVA_HOME in global tool configuration, due to I have some linux slave. Second, if I go with your configuration. I have to choose JDK in every job build confiugration which running in this slave, see my picture http://prntscr.com/p201i8. I want to use a (System) JDK which will get from environment variable in this node, so I can switch to another slave node without changing the JDK option. – Tien Dung Tran Sep 05 '19 at 04:20
  • this issue still occur with method 2, here is my screenshoot http://prntscr.com/p223yl I also tried to restart this server. – Tien Dung Tran Sep 05 '19 at 07:51
  • Please disconnect and then connect the node. – Technext Sep 05 '19 at 08:42
  • unfortunately, this issue still occur. – Tien Dung Tran Sep 05 '19 at 10:47
  • Please update your post with the output of `mvn -v`. Also, _during the build_, can you please print the output of `echo %Path%` – Technext Sep 05 '19 at 11:35
  • here is the output https://pastebin.com/3wvGCTDa I just found out that, If I try to run maven bulid inside this node, it run success. – Tien Dung Tran Sep 09 '19 at 08:17
  • Your statement comes as a surprise where you mention that _...If I try to run maven bulid inside this node, it run success..._ Where were you running the build before then? – Technext Sep 09 '19 at 14:11
  • yes, it's true. When I remote to this server, and open command prompt, cd to workspace folder of this project, let say: C:\jenkins_slave\workspace\project01\, then type the command: mvn clean install, it run without complain about jdk or jre as run from Jenkins. – Tien Dung Tran Sep 10 '19 at 02:59
  • Ok. So if i get it right, your issue is still not resolved. You are able to run commands manually on the node but it's not working through Jenkins, correct? – Technext Sep 10 '19 at 08:06
  • Based on the [Pastebin](https://pastebin.com/3wvGCTDa) link that you shared, it seems you have followed the suggestion i made in Method 2 of my answer. – Technext Sep 10 '19 at 12:54
  • yes, it still not work, I just update my question for the current status. – Tien Dung Tran Sep 11 '19 at 02:46
  • What time are you online? I am available for next 2 hrs. I have SYSTEM enabled in JDK drop-down in my job. Also, in Node's configuration, i only have `Environment variables` set. `Tool Locations` is not set. It's empty and it's working for me. See updated pic in `Method 2` of my answer. – Technext Sep 14 '19 at 07:38
  • I online from 9AM->18PM GMT+7. Please let me know when you avaiable. I also have some Windows slaves like this and the setup is very straighforward, the build job work well without set Environment varaible in Node's confiugration.I tried to clone the worked node, but the issue still occur. So I think this issue may come from Jenkins configuration. – Tien Dung Tran Sep 16 '19 at 03:18
  • I am available usually from 1330 hrs to 1630 hrs GMT. Available right now. – Technext Sep 16 '19 at 13:06
  • How could I chat with you? – Tien Dung Tran Sep 17 '19 at 03:28
  • I'm glad that something finally worked. It was a tricky one! :) – Technext Sep 27 '19 at 13:27