Having problems with Dot.NET Core project and Java in my Azure agent to execute SonarCloud Analisis

Hi, as the title explains I’m having problems running the pipeline with .Net Core and SonarCloud

  • ALM used : Azure DevOps
  • CI system used: Azure DevOps
  • Languages of the repository: C# .NET Core

My pipeline:
trigger:

  • master
    pool: ‘Servers CI’

variables:
solution: ‘**/*.sln’
buildPlatform: ‘Any CPU’
buildConfiguration: ‘Release’

steps:

  • task: UseDotNet@2
    displayName: ‘Install .NET Core SDK’
    inputs:
    version: 3.1.x
    performMultiLevelLookup: true

  • task: SonarCloudPrepare@1
    inputs:
    SonarCloud: ‘Sonarcloud SecCert’
    organization: ‘XXXXXXX’
    scannerMode: ‘MSBuild’
    projectKey: ‘XXXXXXXXXX’
    projectName: ‘SecCert’

  • task: DotNetCoreCLI@2
    displayName: ‘Build solution’
    inputs:
    command: ‘build’
    projects: ‘**/*.sln’
    feedsToUse: ‘select’

  • task: ReviewApp@0
    inputs:
    resourceName: ‘SonarSec’

  • task: SonarCloudAnalyze@1
    displayName: ‘Run SonarCloud analysis’

  • task: SonarCloudPublish@1
    inputs:
    pollingTimeoutSec: ‘300’

The error happens at the moment of running the task: SonarCloudAnalyze@1 and this is literally the result:

  1. 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 SonarScanner did not complete successfully
The SonarScanner did not complete successfully
##[error]18:51:48.442 Post-processing failed. Exit code: 1
18:51:48.442 Post-processing failed. Exit code: 1
##[error]The process ‘C:\Agente Azure_work_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.20.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe’ failed with exit code 1
Finishing: Run SonarCloud analysis

The real problem is that JAVA is installed in the server used for the process (C:\Program Files\Java\jdk-16.0.1\bin) and the variables Path an JAVA_HOME are well explained into the system variables, and also into the capabilities of the agent.

Any suggestion will be appreciated.
Thanks in advance.

Hi @mauro-maulini66712

Can you try to add the path “C:\Program Files\Java\jdk-16.0.1\bin” into a capabitlity of your agent called “java” ?

Mickaël

Maybe a dumb remark, have you put the capability with JAVA or java name ? Not sure it’s case-sensitive, but might worth checking.

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