Scanner mode was not defined error

It is dotbet build

below task failed   - task: SonarQubeAnalyze@7
    displayName: 'SonarQube Run Code Analysis'

with error

##[error][ERROR] SonarQube Server: Error while executing task Analyze: Unknown scanner mode: undefined
##[debug]Processed: ##vso[task.issue type=error;source=TaskInternal;][ERROR] SonarQube Server: Error while executing task Analyze: Unknown scanner mode: undefined
##[debug]task result: Failed
##[error]Unknown scanner mode: undefined

but based on my understanding scanner mode was not defined. but above task is coming from template:

and parameters were given like this

- name: sonar_scan_enabled
  type: boolean
  default: true

- name: scanner_mode
  type: string
  default: 'dotnet'

- name: scanner_config_mode
  type: string
  default: 'manual'

Even though I am using why I am getting below error , please suggest

##[error][ERROR] SonarQube Server: Error while executing task Analyze: Unknown scanner mode: undefined
##[debug]Processed: ##vso[task.issue type=error;source=TaskInternal;][ERROR] SonarQube Server: Error while executing task Analyze: Unknown scanner mode: undefined
##[debug]task result: Failed
##[error]Unknown scanner mode: undefined

Hi SK,

I assume you are running the scan from Azure DevOps Pipelines. The parameters have to be passed to the SonarQubePrepare task. Please refer to the YAML file example in the documentation here - Adding analysis to Azure pipeline for .NET project | SonarQube Server Documentation

Thanks,
Aravind

Aravind,
as I said parameters already given in the below template

Like @aravindnss pointed out, where’s the SonarQubePrepare task?

It is here :slight_smile:

what is wrong.

Okay, these are individual templates for SonarQube. What does your azure-pipelines.yml file look like?

Here is the main:

and in above build template is being called and below is the build template:

Hi Collin,
I was able to fix the java path , but sonar is passing when I choose 17 and 21 JDK versions and it is failing with below error when i choose 8 and 11 JDK versions,

For 11:

#[error]Error: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main
##[debug]Processed: ##vso[task.logissue type=error;]Error: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main
Error: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main
##[error]java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
##[debug]Processed: ##vso[task.logissue type=error;]java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
	java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
##[error]The SonarScanner did not complete successfully
##[debug]Processed: ##vso[task.logissue type=error;]The SonarScanner did not complete successfully
The SonarScanner did not complete successfully
##[error]01:57:17.867  Post-processing failed. Exit code: 1
##[debug]Processed: ##vso[task.logissue type=error;]01:57:17.867  Post-processing failed. Exit code: 1
01:57:17.867  Post-processing failed. Exit code: 1
##[debug]Exit code 1 received from tool 'C:\azp\agent\_work\_tasks\SonarQubePrepare_15b

For 8:

	C:\azp\agent\_work\_temp\ContainerAdministrator_C91430E07ED4_2025-07-08_02_02_16\In\C91430E07ED4\ContainerAdministrator_C91430E07ED4_2025-07-08.02_02_16.coverage
Unique coverage files: count=1
	C:\azp\agent\_work\_temp\768a38ba-7e78-4b97-af74-9018004db19a\ContainerAdministrator_C91430E07ED4_2025-07-08.02_02_16.coverage
Converting coverage file 'C:\azp\agent\_work\_temp\768a38ba-7e78-4b97-af74-9018004db19a\ContainerAdministrator_C91430E07ED4_2025-07-08.02_02_16.coverage' to 'C:\azp\agent\_work\_temp\768a38ba-7e78-4b97-af74-9018004db19a\ContainerAdministrator_C91430E07ED4_2025-07-08.02_02_16.coveragexml'.
Coverage report conversion completed successfully.
The TFS Processor has finished
Calling the SonarScanner CLI...
##[debug]Agent environment resources - Disk: C:\ Available 125241.50 MB out of 129918.98 MB, Memory: Used 39501.00 MB out of 65534.00 MB, CPU: Usage 22.00%
##[error]java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
##[debug]Processed: ##vso[task.logissue type=error;]java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
##[error]at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)

Please suggest fix for this

The scanner requires Java 17+.