Sonar Cloud analysis warning auto generated on PR creation

Below comment is auto generated in PR Comments at the time of PR creation and build is failing due to comment not resolved.

SonarCloud analysis warning for project "****"

WarningThe version of Java (11.0.19) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

Are you using Azure DevOps? Take a look here:

Hi Colin,

When I include SonarCloudAnalyze@1 task in my yaml pipeline it is throwing below error.

Can you share your your pipeline was configured before you made the change?

parameters:
YarnVersion : 1.22.4
NodeVersion: 12.16.3
***Version: 0.0.0.0

jobs:

  • job: SonarCloud
    timeoutInMinutes: 180
    pool:
    vmImage: ubuntu-latest
    workspace:
    clean: all
    variables:
    UTProjects: |
    $(Build.SourcesDirectory)//Tests/UnitTests//.Tests.csproj
    !$(Build.SourcesDirectory)//Tests//TVC.ZeroMQ/*

    steps:

    • script: echo “*** Version ${{parameters.***Version}}”
      displayName: *** Version

    • script: sudo apt-get install libzmq3-dev
      displayName: Install libzmq

    • task: UseNode@1
      inputs:
      version: ${{ parameters.NodeVersion }}

    • pwsh: npm install -g yarn
      displayName: ‘Install yarn’

    • script: yarn set version ${{parameters.YarnVersion}}
      displayName: ‘Set yarn version to ${{parameters.YarnVersion}}’

    • task: npmAuthenticate@0
      displayName: ‘Authenticate contracts for azure feed’
      inputs:
      workingFile: ‘$(Build.SourcesDirectory)/scripts/protobuf/.npmrc’

    • script: |
      java -version
      env:
      JAVA_HOME: $(JAVA_HOME_11_X64)
      PATH: $(JAVA_HOME_11_X64)/bin:$(PATH)

    • script: |
      echo “##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)”
      echo “##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)/bin:$(PATH)”
      displayName: “Set java version”

    • task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
      displayName: ‘Prepare analysis on SonarCloud’
      inputs:
      SonarCloud: SonarServer
      organization: TVCthc
      projectKey: ‘TVC..Server’
      projectName: 'TVC.
      .Server’
      projectVersion: '${{parameters.Version}}’
      extraProperties: |
      # Additional properties that will be passed to the scanner,
      # Put one key=value per line, example:
      sonar.coverage.exclusions =
      /Tests/
      /*.cs,/Program.cs,/Startup.cs,/*HostedService.cs,/DI/*,/TVC.Common/TVC.Configuration/*Settings.cs,/TVC.DI/,/Validators/,/Migration*.cs,/Mappings/*Mapping.cs,/TVC.Managers.Infrastructure/,/TVC.Wireless.Auth/IdentityServerData*,/TVC.Wireless.Auth.Controllers/IdentityServerData/,/TVC.Wireless.Auth.Controllers/RenderData/,Pipelines.Sockets,/SwaggerExamples/, /TVC.History.Services/ElasticService.cs
      sonar.exclusions=
      /Migration/, /Mappings/, /TVC.ThirdParty/, /SwaggerExamples/
      sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/
      /coverage.opencover.xml

    • task: SonarCloudAnalyze@1
      inputs:
      jdkversion: ‘JAVA_HOME_17_X64’

    • task: UseDotNet@2
      displayName: ‘Use dotnet sdk’
      inputs:
      packageType: sdk
      version: 6.0.402

    restore including our own feed.

    • task: DotNetCoreCLI@2
      displayName: ‘dotnet restore’
      inputs:
      command: restore
      feedsToUse: ‘select’
      noCache: true
      projects: ./TVC..Server/TVC..Server.sln
      vstsFeed: ‘fc9c65e4-b8d7-46d4-a46e-4ae6145eecd6’

    • pwsh: |
      dotnet new sln --name _unittest
      Get-ChildItem -Path “$(Get-Location)/TVC..Server/Tests/UnitTests/" -Recurse -File -Include *.csproj | ForEach-Object { dotnet sln unittest.sln add $.FullName.Substring($pathlength) }
      dotnet test _unittest.sln --configuration $(BuildConfiguration) /p:ExcludeByFile="
      /TVC.ThirdParty/
      /*.cs%2c*/SwaggerExamples/**/.cs" /p:Exclude="[xunit]%2c[Pipelines.Sockets]%2c[StackExchange.Redis]%2c[Fluent]%2c[protobuf%2c[].Program%2c[].DI.%2c[.Tests?]%2c[TVC.ZeroMQ.Common]%2c[]TVCContracts%2c[SwaggerExamples]” /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx --results-directory $(Build.StagingDirectory)/TestResults/
      displayName: Run unit tests

    • task: SonarSource.sonarcloud.***.SonarCloudAnalyze@1
      displayName: ‘Run Code Analysis’

    • task: SonarSource.sonarcloud.***.SonarCloudPublish@1
      displayName: ‘Publish Quality Gate Result’

It looks like you have the SonarCloudAnalyze task twice, once without the SonarCloudPrepare task, which is throwing the error you get in the last screenshot you shared.

Hi @Colin ,

Thanks for your inputs, it worked for me after removing one of the SonarCloudAnalyze and made few configurations in yaml file.

1 Like