Sonar run code anlaysist task failed

Error:

ossible causes:

  1. The project has not been built - the project must be built in between the begin and end steps.
  2. An unsupported version of MSBuild has been used to build the project. Supported versions: MSBuild 16 and higher.
  3. The begin, build and end steps have not all been launched from the same folder.
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln).
    ##[debug]Processed: ##vso[task.logissue type=error;]07:16:29.822 The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
    Possible causes:
  5. The project has not been built - the project must be built in between the begin and end steps.
  6. An unsupported version of MSBuild has been used to build the project. Supported versions: MSBuild 16 and higher.
  7. The begin, build and end steps have not all been launched from the same folder.
  8. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln).
    07:16:29.822 The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
    Possible causes:
  9. The project has not been built - the project must be built in between the begin and end steps.
  10. An unsupported version of MSBuild has been used to build the project. Supported versions: MSBuild 16 and higher.
  11. The begin, build and end steps have not all been launched from the same folder.
  12. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln).
    07:16:29.822 Generation of the sonar-properties file failed. Unable to complete the analysis
    - task: SonarQubePrepare@6
      displayName: Prepare analysis on SonarQube
      inputs:
        SonarQube: 'SonarQube'
        scannerMode: 'MSBuild'
        projectKey: 'AzDODemo'
        projectName: 'AzDODemo'
        projectVersion: '$(Version.Major).$(Version.Minor).$(Version.Patch)'
        extraProperties: |
          sonar.branch.name=$(Build.SourceBranchName)
          sonar.qualitygate.wait=true

    - task: SonarQubeAnalyze@6
        displayName: Run Code Analysis
        inputs:
          jdkversion: 'JAVA_HOME_17_X64'
    - task: SonarQubePublish@6
      displayName: Publish Quality Gate Result

Above tasks are used,

  • task: SonarQubeAnalyze@6 ( this is failed task and above error is from this task )
    Please suggest what is wrong

You need to actually build your solution between SonarQubePrepare and SonarQubeAnalyze.

That typically looks something like this:

# Prepare Analysis Configuration task
- task: SonarQubePrepare@7
  inputs:
    SonarQube: '<YourSonarqubeServerEndpoint>'
    scannerMode: 'dotnet'
    projectKey: '<YourProjectKey>'

# Dotnet build task
- task: DotNetCoreCLI@2
  displayName: 'dotnet build'

# Run Code Analysis task
- task: SonarQubeAnalyze@7

(docs)

But I don’t have build task

Well, to analyze .NET code, you need to build your code.

If you’re not analyzing .NET code, you should be using the cli scannerMode.

You can see my intention in build stage is only to validate liquibase command and once that code is validated and I need to publish artifact to jfrog. you can see below tasks I am using and also you can see series of tasks after validate task , and that series of tasks consist above sonar tasks and it gave above error. Could you please suggest what is wrong in below?

Are you analyzing .NET code? Or something else?

If the former – you will have to build your code, and should probably move SonarQube analysis back to the build stage rather than this publishing stage. .NET analysis requires a full build.

It is not dotnet code at all

it is below code where xml file is there on which we liquibase validate command

please suggest now

Then we seem to be back here.

Okay let me check that and will update you

thank you

I have used following tasks: but it is failing at sonaranalysis task it seems:

and I am seeing error as below , Please suggest

##[error]Error: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main
	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;]Error: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main
	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: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main
	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]Process exited with code 1 and signal null for tool 'D:\AzDOAgents\agent2\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\7.1.1\sonar-scanner\bin\sonar-scanner.bat'
##[debug]STDIO streams have closed and received exit code 1 and signal null for tool 'D:\AzDOAgents\agent2\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\7.1.1\sonar-scanner\bin\sonar-scanner.bat'
##[error][ERROR] SonarQube Server: Error while executing task Analyze: The process 'D:\AzDOAgents\agent2\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\7.1.1\sonar-scanner\bin\sonar-scanner.bat' failed with exit code 1
##[debug]Processed: ##vso[task.issue type=error;source=TaskInternal;][ERROR] SonarQube Server: Error while executing task Analyze: The process 'D:\AzDOAgents\agent2\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\7.1.1\sonar-scanner\bin\sonar-scanner.bat' failed with exit code 1
##[debug]task result: Failed
##[error]The process 'D:\AzDOAgents\agent2\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\7.1.1\sonar-scanner\bin\sonar-scanner.bat' failed with exit code 1
##[debug]Processed: ##vso[task.issue type=error;source=TaskInternal;]The process 'D:\AzDOAgents\agent2\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\7.1.1\son

You’ll need to make sure that Java 17 is installed on the build agent, and that this Java installation is pointed to by the JAVA_HOME_17_X64 variable (or the JAVA_HOME environment variable)

In the screenshot you shared in an earlier version of your post, it looks like you have a step that checks for Java 17 that has a warning sign next to it. It’s also clear from that screenshot that JAVA_HOME_17_X64 is undefined.