Azure DevOps SonarQubeAnalyze@5 is not finding java netiher in JAVA_HOME nor PATH

I am trying to run SonarQube in an Azure DevOps Pipeline, in the SonarQubeAnalysis@5 it errors that it cannot find java in either JAVA_HOME nor PATH.

I am pretty sure java is installed and is set as an environment variable in the agent VM.

I suspect the issue is in the wrapper.conf file. Question what is the default location where the wrapper.conf looks for java?
How can I change/update the current location of java in the wrapper.conf in the SonarQubePrepare/extraProperties?
There should be a way for me to change that in the pipeline.

thx, Markus.

Hi Markus,

Welcome to the community!

wrapper.conf is (used to be) part of the installation of SonarQube itself. It’s unrelated to running analysis.

Are you using a Microsoft-hosted build agent or a self-hosted agent? If the former, Java should already be there for you.

Can you provide your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.


I am using self-hosted agent.

By analysis log you mean the error output that the pipeline task SonarQubeAnalyzer produces?

This is what I get from SonarQubeAnalyze@5

2023-05-17T23:50:35.2692807Z ##[section]Starting: SonarQubeAnalyze
2023-05-17T23:50:35.2697081Z ==============================================================================
2023-05-17T23:50:35.2697433Z Task         : Run Code Analysis
2023-05-17T23:50:35.2697517Z Description  : Run scanner and upload the results to the SonarQube server.
2023-05-17T23:50:35.2697653Z Version      : 5.13.0
2023-05-17T23:50:35.2697730Z Author       : sonarsource
2023-05-17T23:50:35.2697812Z Help         : Version: 5.13.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](
2023-05-17T23:50:35.2698083Z ==============================================================================
2023-05-17T23:50:36.4549847Z [command]/agent/_work/_tasks/SonarQubeAnalyze_6d01813a-xxxxxxx/5.13.0/sonar-scanner/bin/sonar-scanner
2023-05-17T23:50:36.4746467Z ##[error]Unrecognized option: -
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
2023-05-17T23:50:36.4747754Z Unrecognized option: -
2023-05-17T23:50:36.4748101Z Error: Could not create the Java Virtual Machine.
2023-05-17T23:50:36.4748459Z Error: A fatal exception has occurred. Program will exit.
2023-05-17T23:50:36.4811335Z ##[error]The process '/agent/_work/_tasks/SonarQubeAnalyze_6d01813a-xxxxxx/5.13.0/sonar-scanner/bin/sonar-scanner' failed with exit code 1
2023-05-17T23:50:36.4851155Z ##[section]Finishing: SonarQubeAnalyze

This is my pipeline.yml:

  - none
pool: $(agent_pool)
- task: Bash@3
    targetType: 'inline'
    script: |
      ls /opt
- task: Bash@3
  displayName: 'Copy code from repo to /agent/_work/temp'
    targetType: 'inline'
    script: |
      mkdir /agent/_work/temp
      cp -R "$(Agent.BuildDirectory)/s/." /agent/_work/temp
      cd  /agent/_work/temp
      ls -l
- task: NodeTool@0
  enabled: true
    versionSpec: '14.x'
  displayName: 'Install node.js'
- script: |
    echo $no_proxy
    npm config set registry
    npm install --legacy-peer-deps
    cd $(Pipeline.Workspace)/s/node_modules/
    rm -rf caniuse-lite
    rm -rf browserslist 
    npm i -g browserslist caniuse-lite --save
  displayName: 'Npm Install'
- script: |
      which node
      node -v
- task: JavaToolInstaller@0
  displayName: 'Install Java'
    versionSpec: '11'
    jdkArchitectureOption: 'x64'
    jdkSourceOption: 'AzureStorage'
    azureResourceManagerEndpoint: 'PROD-ServiceConnection' 
    azureStorageAccountName: 'storage' 
    azureContainerName: 'jdkcontainer' 
    azureCommonVirtualFile: 'openjdk-11.0.2_linux-x64_bin.tar.gz'
- task: SonarQubePrepare@5
  displayName: SonarQubePrepare
    SonarQube: 'sonar-service-connection'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: 'frontend'
    cliProjectName: 'frontend'
    extraProperties: |
     sonar.exclusions=**test/**, **node_modules/**
  continueOnError: true
- task: Docker@0
  enabled: true
  displayName: 'Build an image'
    azureSubscription: 'subscription'
    azureContainerRegistry: '{"loginServer":"", "id" : "/subscriptions/xxxxx/resourceGroups/nprd-devops-rg/providers/Microsoft.ContainerRegistry/registries/hithere"}'
    dockerFile: '/agent/_work/temp/Dockerfile'
- task: SonarQubeAnalyze@5
  displayName: SonarQubeAnalyze
  continueOnError: true
- task: SonarQubePublish@5
  displayName: SonarQubePublish
  continueOnError: true


Since you’re using a self-hosted agent, you’ll need to make sure Java is installed on it and (I believe) in %PATH%.