Could not find 'java' executable in JAVA_HOME or PATH (but it is correctly set)

Hello,

After updating my build agent (CentOs) packages (it did an update of OpenJdk), it is not possible anymore to use the AzureDevops plugin Code Analysis (the prepare step do work).

I checked and adjusted the path and javaq_home variable for all users, without improvement.
I did the jdk update on another buildAgent: same, not working anymore.

Any idea ?

Error:

Starting: Run Code Analysis - community
==============================================================================
Task         : Run Code Analysis - community
Description  : Run scanner and upload the results to the SonarQube server.
Version      : 4.8.0
Author       : community-sonarsource
Help         : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html) - community
==============================================================================
/usr/bin/dotnet /var/vstsagent/_work/_tasks/SonarQubePrepareCommunityCommunity_33f55862-2cc1-4321-a3e5-6ff3d3f8600b/4.8.0/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll end
SonarScanner for MSBuild 4.7.1
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarQube Scanner...
Could not find 'java' executable in JAVA_HOME or PATH.
##[error]The SonarQube Scanner did not complete successfully
The SonarQube Scanner did not complete successfully
##[error]04:55:57.429  Post-processing failed. Exit code: 1
04:55:57.429  Post-processing failed. Exit code: 1
##[error]The process '/usr/bin/dotnet' failed with exit code 1
Finishing: Run Code Analysis - community

Environment variables just before the call to the scanner:

PATH:

/usr/lib/jvm/java-11-openjdk-11.0.14.1.1-1.el7_9.x86_64/bin/:/opt/maven/bin:/opt/maven/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vnext/.dotnet/tools:/home/user/.local/bin:/home/user/bin

JAVA_HOME:

/usr/lib/jvm/java-11-openjdk-11.0.14.1.1-1.el7_9.x86_64

java --version

openjdk 11.0.14.1 2022-02-08 LTS

OpenJDK Runtime Environment 18.9 (build 11.0.14.1+1-LTS)

OpenJDK 64-Bit Server VM 18.9 (build 11.0.14.1+1-LTS, mixed mode, sharing)

mvn --version

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

Maven home: /opt/maven

Java version: 11.0.14.1, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.14.1.1-1.el7_9.x86_64

Default locale: en_US, platform encoding: UTF-8

OS name: "linux", version: "3.10.0-1160.59.1.el7.x86_64", arch: "amd64", family: "unix"

which java

/usr/lib/jvm/java-11-openjdk-11.0.14.1.1-1.el7_9.x86_64/bin/java

Hey there.

It doesn’t appear that you’re using the official SonarScanner for Azure DevOps, but instead some community fork?

If you’re doing this to circumvent some license restrictions – sorry, you aren’t going to be able to find help in this community. If you switch to the official Scanner for Azure DevOps, we’ll be happy to help.

Hello Colin, so, this plugin is non-official and not authorized ?
Honnestly did not even noticed that it is not the official one if it isn’t.

Hi Colin,

So, i switched all my pipelines to the official version (i am not using the PR decoration part anyway so using an alternate version is not a benefit, no idea why i used this version in first place several years ago, maybe i was not able to make the official working so i tried randomly everything else…)

Starting: Run Code Analysis
==============================================================================
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarQube server.
Version      : 5.4.0
Author       : sonarsource
Help         : Version: 5.4.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
/usr/bin/dotnet /var/vstsagent/_work/_tasks/SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157/5.4.0/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll end
SonarScanner for MSBuild 5.5.3
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI...
Could not find 'java' executable in JAVA_HOME or PATH.
##[error]The SonarScanner did not complete successfully
The SonarScanner did not complete successfully
##[error]02:56:33.534  Post-processing failed. Exit code: 1
02:56:33.534  Post-processing failed. Exit code: 1
##[error]The process '/usr/bin/dotnet' failed with exit code 1
Finishing: Run Code Analysis

and i have the very same error. This is puzzeling me as obviously it come from my agent setup, but all the values seems correct to me. The only borderline point is that i am using CentOs 7 hosts, that are now somehow old / deprecated.

Answer to myself (may help others):

By enabling the debug mode i was able to progress and notice that the task was not using the agent variables expected (even if defined correctly everywere, like in /etc/profile, .bashrc, forced by a shell step before the SQ step).

##[debug]SONARQUBE_SCANNER_MODE=MSBuild
##[debug]JAVA_HOME=/usr/lib/jvm/java-14-openjdk-14.0.1.7-2.rolling.el7.x86_64
##[debug]JAVA_HOME_11_X64=undefined

Fun fact: i can’t find this version of java on my agent…

But in the agent capability the java_home is indeed wrong:

In theory the agent should refresh this value by taking it from the OS, and in my case it doesn’t…

After many attempts to have the JAVA_HOME correctly detected, i have finally an alternate solution, by setting in the user defined capabilities the JAVA_HOME_11_X64 variable.

:rocket:

2 Likes