Azure DevOps complaining that JAVA_HOME is not set

Build fails while executing “Run Code Analysis”
Pool: Azure Pipelines
Agent: Hosted Agent

Starting: Run Code Analysis

Task : Run Code Analysis
Description : Run scanner and upload the results to the SonarCloud server.
Version : 1.9.0
Author : 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

[command]D:\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.9.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 4.7.1
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.

Calling the SonarQube Scanner...

ERROR: JAVA_HOME not found in your environment, and no Java
       executable present in the PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation, or add "java.exe" to the PATH

##[error]The SonarQube Scanner did not complete successfully
The SonarQube Scanner did not complete successfully
##[error]10:03:46.845  Post-processing failed. Exit code: 1
10:03:46.845  Post-processing failed. Exit code: 1
##[error]The process 'D:\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.9.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe' failed with exit code 1
##[section]Finishing: Run Code Analysis

Hi @gmoulin and welcome to the community !

Are you sure that the logs comes from an MS-Hosted agent ? If yes, can you give me the image name ? Given the paths, i would rather say that it comes from a self-hosted one.

Message is pretty clear then, the JAVA_HOME is either not set or not accessible from the user that runs the pipeline. Can you check by adding a powershell script with the corresponding inline script :

Write-Host "JAVA_HOME : $env:JAVA_HOME"
& java --version

And see the result ?

Thanks.

Mickaël

Hi @mickaelcaro.

This had been executed directly in the cloud in an Azure DevOps pipieline, we don"t have an on-premise build server.

Regards

Which image version are you using ?

Was using win1803. It works with windows-2019.
Thanks @mickaelcaro

1 Like

Perfect ! Don’t know why they didn’t set JAVA_HOME in this particular flavor, but glad that it works.

Thank you.

1 Like