Sonar scanner for .NET Core in Jenkins Pipeline

Hi all,

I’m facing an issue triggering sconascanner for dotnet from my Jenkins pipeline
I’m not able to dynamically set the project Key during the scan ‘/k:’ for the projectKey
How can I fetch the project key? I’m looking at something like the below to trigger my scan where ${project_key} can be obtained from the project

bat label: ‘’, script: “cmd.exe /C dotnet sonarscanner begin /k:{project_key} /d:sonar.host.url={buildConfig.sonarUrl} /d:sonar.login=${sonarkey}”

Also, When I try to include sonar-project.properties in the repo, the execution fails with the following error

Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
sonar-project.properties files are not understood by the SonarScanner for MSBuild

Thanks,
Krishna

Hello @krishnaarani
From what I understand, there is two questions here :
1.

Your projectKey can be retrieved from your SonarQube project overview, here :

Yes, with the scanner for MSBuild, you pass all parameters from the command-line, exactly the way you did it.

Hope to help.
Regards,

Christophe

Thanks Christophe

I was looking at a dynamic way to fetch the “project-key” to trigger the scan through Jenkins pipeline.
After adding the “PackageReference” in the .csproj for sonarqube scanner tool, a “.sonarqube” folder gets generated with the run which contains “SonarQubeAnalysisConfig.xml” containing all the sonarqube configurations, including the SonarProjectKey. Looks something like below. My question was more towards, how I can grab the Project key from the properties into the SonarScanner “/k:” while we trigger the scan

PackageReference

<PackageReference Include="MSBuild.SonarQube.Runner.Tool" Version="4.8.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.9.0.19135">
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  <PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="SonarQube.Scanner.DotNetCore.Tool" Version="4.3.1" />

SonarQubeAnalysisConfig.xml

<?xml version="1.0" encoding="utf-8"?> <--> <--> <--> <--> true <--> 8.1.0.31237 <--> 8.6.1.17183 true .ts,.tsx .groovy SonarQube false false 60 true target/jacoco-it.exec SonarAnalyzer.CSharp false false .css,.less,.scss false And many more propreties....

Thanks,
Krishna