ERROR: JAVA_HOME exists but does not point to a valid Java home folder

  • ALM used (Azure DevOps)
  • CI system used (Azure DevOps)
2024-01-11T18:04:04.5004071Z ##[debug]Evaluating condition for step: 'Run Code Analysis'
2024-01-11T18:04:04.5005119Z ##[debug]Evaluating: succeeded()
2024-01-11T18:04:04.5005355Z ##[debug]Evaluating succeeded:
2024-01-11T18:04:04.5005830Z ##[debug]=> True
2024-01-11T18:04:04.5006164Z ##[debug]Result: True
2024-01-11T18:04:04.5006463Z ##[section]Starting: Run Code Analysis
2024-01-11T18:04:04.5169757Z ==============================================================================
2024-01-11T18:04:04.5169918Z Task         : Run Code Analysis
2024-01-11T18:04:04.5170009Z Description  : Run scanner and upload the results to the SonarCloud server.
2024-01-11T18:04:04.5170115Z Version      : 1.43.2
2024-01-11T18:04:04.5170400Z Author       : sonarsource
2024-01-11T18:04:04.5170468Z Help         : Version: 1.43.2. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
2024-01-11T18:04:04.5170772Z ==============================================================================
2024-01-11T18:04:04.5567428Z ##[debug]Using node path: D:\Agent2\externals\node10\bin\node.exe
2024-01-11T18:04:06.1489858Z ##[debug]agent.TempDirectory=D:\Agent2\_work\_temp
2024-01-11T18:04:06.1550317Z ##[debug]loading inputs and endpoints
2024-01-11T18:04:06.1568620Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2024-01-11T18:04:06.1590694Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2024-01-11T18:04:06.1594682Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2024-01-11T18:04:06.1597933Z ##[debug]loading INPUT_JDKVERSION
2024-01-11T18:04:06.1603366Z ##[debug]loading SECRET_SONARQUBE_ENDPOINT
2024-01-11T18:04:06.1610554Z ##[debug]loaded 5
2024-01-11T18:04:06.1616730Z ##[debug]Agent.ProxyUrl=undefined
2024-01-11T18:04:06.1618239Z ##[debug]Agent.CAInfo=undefined
2024-01-11T18:04:06.1618614Z ##[debug]Agent.ClientCert=undefined
2024-01-11T18:04:06.1618957Z ##[debug]Agent.SkipCertValidation=undefined
2024-01-11T18:04:06.4455184Z ##[debug]jdkversion=JAVA_HOME
2024-01-11T18:04:06.4460994Z ##[debug]SONARQUBE_SCANNER_MODE=MSBuild
2024-01-11T18:04:06.4462337Z ##[debug]JAVA_HOME was specified in the Run Code Analysis task configuration, nothing to do.
2024-01-11T18:04:06.4464714Z ##[debug]SONARQUBE_SCANNER_PARAMS={"sonar.host.url":"https://sonarcloud.io/","sonar.token":***,"sonar.organization":"distributionmgmt","sonar.projectKey":"API.DM","sonar.projectName":"API.DM","sonar.projectVersion":"1.0","sonar.scanner.metadataFilePath":"D:\\Agent2\\_work\\_temp\\sonar\\213642\\711a7720-642c-620f-1f9b-3264946193be\\report-task.txt"}
2024-01-11T18:04:06.4470653Z ##[debug]SONARQUBE_SCANNER_MSBUILD_EXE=D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe
2024-01-11T18:04:06.4475155Z ##[debug]which 'D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'
2024-01-11T18:04:06.4500864Z ##[debug]found: 'D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'
2024-01-11T18:04:06.4502779Z ##[debug]D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe arg: end
2024-01-11T18:04:06.4506978Z ##[debug]exec tool: D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe
2024-01-11T18:04:06.4507420Z ##[debug]arguments:
2024-01-11T18:04:06.4507720Z ##[debug]   end
2024-01-11T18:04:06.4517624Z [command]D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
2024-01-11T18:04:06.6754538Z SonarScanner for MSBuild 5.14
2024-01-11T18:04:06.6757978Z Using the .NET Framework version of the Scanner for MSBuild
2024-01-11T18:04:06.7749268Z Post-processing started.
2024-01-11T18:04:08.0371127Z Calling the TFS Processor executable...
2024-01-11T18:04:08.2409548Z Attempting to locate the CodeCoverage.exe tool...
2024-01-11T18:04:08.2446340Z Attempting to locate the CodeCoverage.exe tool using setup configuration...
2024-01-11T18:04:08.3136167Z Attempting to locate the CodeCoverage.exe tool using registry...
2024-01-11T18:04:08.3204826Z WARNING: Failed to find the code coverage command line tool. Possible cause: Visual Studio is not installed, or the installed version does not support code coverage.
2024-01-11T18:04:08.3298376Z The TFS Processor has finished
2024-01-11T18:04:08.3363048Z Using the supplied value for SONAR_SCANNER_OPTS. Value: -Xmx1024M
2024-01-11T18:04:08.3364754Z Calling the SonarScanner CLI...
2024-01-11T18:04:08.4195166Z 
2024-01-11T18:04:08.4199103Z ERROR: JAVA_HOME exists but does not point to a valid Java home
2024-01-11T18:04:08.4204042Z        folder. No "\bin\java.exe" file can be found there.
2024-01-11T18:04:08.4220064Z 
2024-01-11T18:04:08.4360140Z ##[error]The SonarScanner did not complete successfully
2024-01-11T18:04:08.4360756Z ##[debug]Processed: ##vso[task.logissue type=error;]The SonarScanner did not complete successfully
2024-01-11T18:04:08.4361154Z The SonarScanner did not complete successfully
2024-01-11T18:04:08.4361640Z ##[error]12:04:08.433  Post-processing failed. Exit code: 1
2024-01-11T18:04:08.4361996Z ##[debug]Processed: ##vso[task.logissue type=error;]12:04:08.433  Post-processing failed. Exit code: 1
2024-01-11T18:04:08.4362302Z 12:04:08.433  Post-processing failed. Exit code: 1
2024-01-11T18:04:08.4512127Z ##[debug]Exit code 1 received from tool 'D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'
2024-01-11T18:04:08.4522338Z ##[debug]STDIO streams have closed for tool 'D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'
2024-01-11T18:04:08.4728472Z ##[debug]task result: Failed
2024-01-11T18:04:08.4729870Z ##[error]The process 'D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe' failed with exit code 1
2024-01-11T18:04:08.4730582Z ##[debug]Processed: ##vso[task.issue type=error;]The process 'D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe' failed with exit code 1
2024-01-11T18:04:08.4732173Z ##[debug]Processed: ##vso[task.complete result=Failed;]The process 'D:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe' failed with exit code 1
2024-01-11T18:04:08.4806723Z ##[section]Finishing: Run Code Analysis
  • Steps to reproduce
    I am creating my first sonarcloud analysis and get this same issue every time. I have validated the JAVA_HOME path exists. when i run echo %JAVA_HOME% I get “C:\Program Files\Java\jdk-17”.
    \bin\java.exe exists in that location.
    I’m at a loss!

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hey there.

JAVA_HOME should point to a folder (which contains bin\java.exe, not the executable itself. I know – so confusing! We weren’t asked about this convention. :smiley:

hi Colin, please take a look at my post again. I show that %JAVA_HOME% is pointing to a directory. then i state that bin\java.exe exists in that location.

Sorry, it was too easy to see this as one continous strign.

Where are you running this, and how? On the Azure DevOps build agent?

If you’re running it manually, try running it in the context of your build (with a CmdLine task, for example)

we have two on-prem build machines hosting build agents.

I am logging onto our build machine using the same account that the build agents use. running cmd and then "echo %JAVA_HOME%
I also double checked the system environment variables are configured (it’s not a user specific environment variable)
I took your advice and ran this from the build agent itself. you’re right, it’s definitely not the correct path!.
any ideas why this wouldn’t match system settings?

fyi in case you missed my edit of my last reply. you were correct and that was a good suggestion to have the build agent run the echo command directly. it did show somewhere different!
any ideas on where that’s coming from? like i said before i already have JAVA_HOME mapped within the system environment variables

It might have something to do with what version of the Azure DevOps agent you have deployed (https://github.com/microsoft/azure-pipelines-agent). Can you check to see if it’s up to date?

yeah i thought that might be involved as well. all build agents are running version 3.232.1 with the same result

I found it! someone had an overriding variable defined in the build that i didn’t see before. once I removed it, it reverted to using the environment variable.
Thanks for your help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.