C#, Jenkins and Sonar

Good morning, how are you ? I need some help. I’m trying to set up sonarQube on jenkins, but my language is C # and I’m not getting it. Would you help me?

Hi,

What have you tried? Have you seen the docs?

 
Ann

1 Like

Yes! I have already seen and try to try everything, but it is really a problem to configure the parameters that is giving error. I really do not know what it can be. The last error in jenkins was this:

"Iniciado pelo usuário Joana Carrasco
Construindo no workspace C:\Program Files (x86)\Jenkins\workspace\teste_sonar
using credential <EDITED>
 > C:\Program Files\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > C:\Program Files\Git\bin\git.exe config remote.origin.url https://dev-targetmp@bitbucket.org/devtargetmp/jenkins-poc.git # timeout=10
Fetching upstream changes from https://dev-targetmp@bitbucket.org/devtargetmp/jenkins-poc.git
 > C:\Program Files\Git\bin\git.exe --version # timeout=10
using GIT_ASKPASS to set credentials 
 > C:\Program Files\Git\bin\git.exe fetch --tags --force --progress https://dev-targetmp@bitbucket.org/devtargetmp/jenkins-poc.git +refs/heads/*:refs/remotes/origin/*
 > C:\Program Files\Git\bin\git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > C:\Program Files\Git\bin\git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision <EDITED>(refs/remotes/origin/master)
 > C:\Program Files\Git\bin\git.exe config core.sparsecheckout # timeout=10
 > C:\Program Files\Git\bin\git.exe checkout -f <EDITED>
Commit message: "Merged in sprint91/FRETE-4072-jenkins---prova-de-conceito (pull request #teste35)"
 > C:\Program Files\Git\bin\git.exe rev-list --no-walk <EDITED># timeout=10
[teste_sonar] $ "C:\Program Files (x86)\Jenkins\tools\hudson.plugins.sonar.MsBuildSQRunnerInstallation\SonarQube_Scanner_msbuild_4.6.1.2049\SonarScanner.MSBuild.exe" begin /k:ByteBank /n:ByteBank /v:1.0 /d:sonar.host.url=<EDITED>/sonar
SonarScanner for MSBuild 4.6
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
11:18:35.225  Updating build integration targets...
11:18:35.249  Fetching analysis configuration settings...
11:18:35.31  Failed to request and parse 'http://<EDITED>/sonar/api/server/version': A parte da cadeia de caracteres da versÆo era muito curta ou muito longa.

Exce‡Æo Sem Tratamento: System.ArgumentException: A parte da cadeia de caracteres da versÆo era muito curta ou muito longa.
   em System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
   em System.Version.TryParseVersion(String version, VersionResult& result)
   em System.Version.Parse(String input)
   em System.Version..ctor(String version)
   em SonarScanner.MSBuild.PreProcessor.SonarWebService.<>c__DisplayClass15_0.<DownloadServerVersion>b__0()
   em SonarScanner.MSBuild.PreProcessor.SonarWebService.DoLogExceptions[T](Func`1 op, String url, Action`1 onError)
   em SonarScanner.MSBuild.PreProcessor.SonarWebService.DownloadServerVersion()
   em SonarScanner.MSBuild.PreProcessor.SonarWebService.GetServerVersion()
   em SonarScanner.MSBuild.PreProcessor.SonarWebService.GetProperties(String projectKey, String projectBranch)
   em SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.FetchArgumentsAndRulesets(ISonarQubeServer server, ProcessedArgs args, TeamBuildSettings settings, IDictionary`2& serverSettings, List`1& analyzersSettings)
   em SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs localSettings)
   em SonarScanner.MSBuild.BootstrapperClass.PreProcess()
   em SonarScanner.MSBuild.BootstrapperClass.Execute()
   em SonarScanner.MSBuild.Program.Execute(String[] args, ILogger logger)
   em SonarScanner.MSBuild.Program.Main(String[] args)
ERROR: Execution of SonarScanner for MSBuild failed (exit code -532.462.766)
Finished: FAILURE" 

I started using the tool recently and I really do not know where I might be going wrong. Can you guide me?

Hi,

Not expecting to get there, I tried the URL in your error message: http://:9000/sonar/api/server/version. In fact, your SonarQube instance is available on the internet, so I was able to see that http://:9000/sonar/api/server/version is 404, and that http://:9000/api/server/version is not. It looks like you’ve misconfigured your server in Jenkins at the global level. Remove “/sonar” from the URL and you’ll probably be good to go.

 
Ann

1 Like

Thank you for your help. Now my problem is in the sonar scanner configuration, I’m almost there. Would you help me with this setup?
Now the following message appeared:

"Started by user Joana Carrasco
Building in the C: \ Program Files (x86) workspace \ Jenkins \ workspace \ test_sonar
using credential <EDITED>
 > C: \ Program Files \ Git \ bin \ git.exe rev-parse --is-inside-work-tree # timeout = 10
Fetching changes from the remote Git repository
 > C: \ Program Files \ Git \ bin \ git.exe config remote.origin.url https: //dev-targetmp@bitbucket.org/devtargetmp/jenkins-poc.git # timeout = 10
Fetching upstream changes from https: //dev-targetmp@bitbucket.org/devtargetmp/jenkins-poc.git
 > C: \ Program Files \ Git \ bin \ git.exe --version # timeout = 10
using GIT_ASKPASS to set credentials
 > C: \ Program Files \ Git \ bin \ git.exe fetch --tags --force --progress https: //dev-targetmp@bitbucket.org/devtargetmp/jenkins-poc.git + refs / heads / *: refs / remotes / origin / *
 > C: \ Program Files \ Git \ bin \ git.exe rev-parse "refs / remotes / origin / master commit" # timeout = 10
 > C: \ Program Files \ Git \ bin \ git.exe rev-parse "refs / remotes / origin / origin / master commit" # timeout = 10
Checking out Revision <EDITED>(refs / remotes / origin / master)
 > C: \ Program Files \ Git \ bin \ git.exe config core.sparsecheckout # timeout = 10
 > C: \ Program Files \ Git \ bin \ git.exe checkout -f <EDITED>
Commit message: "Merged in sprint91 / FRETE-4072-jenkins --- proof of concept (pull request # teste35)"
 > C: \ Program Files \ Git \ bin \ git.exe rev-list -no-walk <EDITED># timeout = 10
"SonarScanner.msbuild.exe" / / ByteBank / n: ByteBank / v: C: \ Program Files (x86) \ Jenkins \ tools \ hudson.plugins.sonar.MsBuildSQRunnerInstallation \ SonarQube_Scanner_msbuild_4.6.1.2049 \ 1.0 /d:sonar.host.url=<EDITED>
SonarScanner for MSBuild 4.6
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories ...
14: 06: 17.378 Updating build integration targets ...
14: 06: 17,408 Fetching analysis configuration settings ...
14: 06: 18.014 Provisioning analyzer assemblies for cs ...
14: 06: 18.016 Installing required Roslyn analyzers ...
14: 06: 18.167 Pre-processing succeeded.
[test_sonar] $ cmd / c call C: \ WINDOWS \ TEMP \ jenkins5401364299912095560.bat

C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar> "C: \ Program Files (x86) \ MSBuild \ 14.0 \ Bin \ MSBuild.exe" / t: Rebuild
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/ m" switch.
Build started 05/30/2019 14:06:19.
Project "C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \ ByteBank.sln" on node 1 (Rebuild target (s)).
ValidateSolutionConfiguration:
  Building solution configuration "Debug | Any CPU".
The target "RazorCoreCompile" listed in a BeforeTargets attribute at "C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \ .sonarqube \ bin \ targets \ SonarQube.Integration.targets (453,49)" does not exist in the project, and will be ignored.
C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \ ByteBank \ ByteBank.csproj "(2)" C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \ ByteBank.sln " ) on node 1 (Rebuild target (s)).
GenerateBindingRedirects:
  No suggested binding redirects from ResolveAssemblyReferences.
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CreateProjectSpecificDirs:
  Creating directory "C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \ .sonarqube \ conf \ 0".
SetRoslynCodeAnalysisProperties:
  External issues are not supported on this version of SonarQube. SQv7.4 + is required.
CoreCompile:
C: \ Program Files (x86) \ MSBuild \ 14.0 \ bin \ csc.exe / noconfig / nowarn: 1701,1702 / nostdlib + / platform: anycpu32bitpreferred / errorreport: prompt / warn: 4 / define: DEBUG; TRACE / highentropyva + / reference C: \ Program Files (x86) \ Reference \ Microsoft \ Framework \ .NET Framework \ v4.6.1 \ Microsoft.CSharp.dll " C: \ Program Files (x86) \ Reference \ "C: \ Program Files \ Microsoft \ Framework \ .NETFramework \ v4.6.1 \ mscorlib.dll" / reference: : \ Program Files (x86) \ Reference \ Program Files \ Microsoft \ Framework \ .NETFramework \ v4.6.1 \ System.Data.DataSetExtensions.dll "/ reference:" C: \ Program Files \ C: \ Program Files \ Microsoft \ Framework \ .NET Framework \ v4.6.1 \ System.Data.dll "/ reference:" C: \ Program Files (x86) \ Program Files (x86) \ Reference Files \ Microsoft \ Framework \ .NETFramework \ v4.6.1 \ System.Net.Http.dll " C: \ Program Files (x86) \ Reference Files \ Microsoft \ Framework \ .NETFramework \ v4.6.1 \ System.Xml.dll " C: \ Program Files \ System.Xml.Linq.dll "/ debug + / debug: full / filealign: 512 / optimize- /out:obj\Debug\ByteBank.exe / ruleset: x86) \ Jenkins \ workspace \ test_sonar \ .sonarqube \ conf \ SonarQubeRoslyn-cs.ruleset "/ errorlog:" C: \ Program Files (x86) \ Jenkins \ workspace \ testson \ ByteBank \ bin \ Debug \ ByteBank.exe.RoslynCA .json "/subsystemversion:6.00 / target: exe / warnaserror- / utf8output /analyzer:C:\WINDOWS\TEMP\.sonarqube\resources\2\Google.Protobuf.dll /analyzer:C:\WINDOWS\TEMP\.sonarqube \ resources \ 2 \ SonarAnalyzer.CSharp.dll
/analyzer:C:\WINDOWS\TEMP\.sonarqube\resources\2\SonarAnalyzer.dll / additionalfile: "C: \ Program Files (x86) \ Jenkins \ workspace \ sonar_test \ .sonarqube \ conf \ cs \ SonarLint.xml" / additionalfile: "C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \. sonarqube \ conf \ 0 \ ProjectOutFolderPath.txt" Officials \ Auxiliar.cs Officials \ Developer.cs Officials \ Designer.cs Officials \ Director.cs \ C: \ WINDOWS \ TEMP \ .NETFramework, \ C: \ WINDOWS \ TEMP \ .NETFramework \ C: \ WINDOWS \ TEMP \ .NETFramework \ Version = v4.6.1.AssemblyAttributes.cs "
  Using shared compiler with compiler from directory: C: \ Program Files (x86) \ MSBuild \ 14.0 \ Bin
Program.cs (15,13): warning S125: Remove this commented out code. [C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test \ ByteBank \ ByteBank.csproj]
Program.cs (11,11): warning S1118: Add a 'protected' constructor or the 'static' keyword to the class declaration. [C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test \ ByteBank \ ByteBank.csproj]
Officials \ OfficialAutenticavel.cs (14,9): warning S3442: Change the visibility of this constructor to 'protected'. [C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test \ ByteBank \ ByteBank.csproj]
Employees \ Official.cs (17,9): warning S3442: Change the visibility of this constructor to 'protected'. [C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test \ ByteBank \ ByteBank.csproj]
_CopyAppConfigFile:
Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
  Copying file from "obj \ Debug \ ByteBank.exe" to "bin \ Debug \ ByteBank.exe".
  ByteBank -> C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test \ ByteBank \ bin \ Debug \ ByteBank.exe
  Copying file from "obj \ Debug \ ByteBank.pdb" to "bin \ Debug \ ByteBank.pdb".
Done Building Project "C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \ ByteBank \ ByteBank.csproj" (Rebuild target (s)).
Done Building Project "C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \ ByteBank.sln" (Rebuild target (s)).

Build succeeded.

"C: \ Program Files (x86) \ Jenkins \ workspace \ testsonson \ ByteBank.sln" (Rebuild target) (1)
C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \ ByteBank \ ByteBank.csproj "(Rebuild target) (2)
(CoreCompile target) ->
  Program.cs (15,13): warning S125: Remove this commented out code. [C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test \ ByteBank \ ByteBank.csproj]
  Program.cs (11,11): warning S1118: Add a 'protected' constructor or the 'static' keyword to the class declaration. [C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test \ ByteBank \ ByteBank.csproj]
  Officials \ OfficialAutenticavel.cs (14,9): warning S3442: Change the visibility of this constructor to 'protected'. [C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test \ ByteBank \ ByteBank.csproj]
  Employees \ Official.cs (17,9): warning S3442: Change the visibility of this constructor to 'protected'. [C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test \ ByteBank \ ByteBank.csproj]

    4 Warning (s)
    0 Error (s)

Time Elapsed 00: 00: 10.06

C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar> exit 0
[test_sonar] $ "C: \ Program Files (x86) \ Jenkins \ tools \ hudson.plugins.sonar.MsBuildSQRunnerInstallation \ SonarQube_Scanner_msbuild_4.6.1.2049 \ SonarScanner.MSBuild.exe" end
SonarScanner for MSBuild 4.6
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
sonar-project.properties files are not understood by the SonarScanner for MSBuild. Remove files from the following folders: C: \ Program Files (x86) \ Jenkins \ workspace \ test_sonar \ ByteBank
14: 06: 29.877 Post-processing failed. Exit code: 1
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
ERROR: Execution of SonarScanner for MSBuild failed (exit code 1)
Finished: FAILURE

Hi,

I’m glad you’re making progress. It will make it easier to help you if you’ll code-format (``` on the line before and the line after) your logs in future posts. I’ve edited your posts so far to do that for you. The logs are unreadable without it.

From your log I notice a couple of things. First you clearly call the scanner twice, but in the first instance, I don’t see the begin command. Was it truly missing, or did it just disappear somewhere in the copy/paste?

Also, I see some warnings about sonar-project.properties

I’m not certain that’s a blocker, but could you remove the file and try again? And finally, it would be usefully to turn on debug logging. Try adding this to your end command: /d:sonar.verbose=true.

 
Ann

Ann,

I do not know how to thank you, all this help. Now I think the problem is in my file path, would you know to help me describe this windows path in the right way? I’m almost there, with your incredible help.

# metadata required
sonar.projectKey = ByteBank
sonar.projectName = ByteBank
sonar.projectVersion = 1,0

# path to source codes
# paths can be separated by commas
sonar.sources = "C: \ Program Files (x86) \ Jenkins \ workspace \ sonar test" $ JOB_NAME / ByteBank

Hi,

Generally, I’d say that your source path shouldn’t be absolute, but instead relative to the directory where analysis is taking place. However, you’re using the Scanner for MSBuild, and that path should be read automatically from the build itself. This is part of why you sandwich the build command with scanner commands. The first sets up eavesdropping on the build to pick up stuff like where the sources are, and the second runs analysis with the collected data. So you shouldn’t need to format, or even provide this value at all.

 
Ann

1 Like

Ann, I got your point. I removed the path and actually still connednuo with problem in SonarScanner. I think you want some configuration. = /

I’m sorry for the way, but I’m quite lost, but I will not give up …

Look at the error this time:

"ERROR: Error while running SonarQube Scanner
ERROR: You must set the following mandatory properties for ‘ByteBank’: sonar.sources
ERROR:
ERROR: Run the SonarQube Scanner again using the -X switch to enable full debug logging.
WARN: Can not find ‘report-task.txt’ in workspace. Was SonarScanner successful?
ERROR: The SonarQube scanner came out with non-zero code: 1
Finished: FAILURE "

I’m even embarrassed … Thank you one more time, see?

You got that error from the SonarScanner for MSBuild?

 
Ann

1 Like

Yes, I’m using it, because my language is C #.

Only I’m not understanding what the problem is, or where I’m wrong in the configuration

I also noticed that my JOB information is not going to my directory in the cloud
localhost: 9000

Can you tell me why? That’s why I think I forgot something.

Hi,

Can you share the job configuration, please? Rather than trying to read what’s being called with what arguments out of the logs, this will be simpler.

 
Thx,
Ann

Ann,

How do I do this? Yes, I would, but I really do not know how to do it.

https://drive.google.com/drive/folders/1ae8BCV0U2RjoJA0B-4YFrCqvBtRvz0WP?usp=sharing

would it be this ?

job configuration

Now I’m going to send you the general configuration of jenkins, sorry for the amount of image

Global configuration

Hi @Joana_Carrasco .

It seems that you have the “Execute SonarQube Scanner” in your job config (before the “SonarScanner for MSBuild - End Analysis”) and this is probaby the cause of this issue.

If you really need to set additional properties in the analysis, you can pass them using the format /d:<property>=<value> in the “SonarScanner for MSBuild - Begin Analysis” like this:

(But I would leave this for later, try to configure an analysis without any additional argument first)

Your job just need these steps:

  • SonarScanner for MSBuild - Begin Analysis
  • Executar no comando do Windows
  • SonarScanner for MSBuild - End Analysis

I hope this helps.

3 Likes

Felipe, thanks for the help!
Sorry for the delay! But the same thing with your documentation is giving error. Can you help me?

Here is the current error:

"INFO: Project Root Configuration File: NONE
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_211 Oracle Corporation (64-bit)
INFO: Windows 10 10.0 amd64
INFO: User Cache: C: \ WINDOWS \ system32 \ config \ systemprofile \ .sonar \ cache
INFO: SonarQube 6.7.7 Server
INFO: Default location: “en_US”, coded source code: “windows-1252” (the analysis depends on the platform)
INFO: Publishing Mode
INFO: Load Global Settings
INFO: Load Global Settings (Completed) | time = 126 ms
INFO: Server ID: BF41A1F2-AWsFJUlZy7MPVk0srGtW
INFO: User Cache: C: \ WINDOWS \ system32 \ config \ systemprofile \ .sonar \ cache
INFO: Upload index of plugins
INFO: Load Index of Plugins (Completed) | time = 91ms
INFO: Process Project Properties
INFO: ------------------------------------------------ ------------------------
INFO: IMPLEMENTATION FAILURE
INFO: ------------------------------------------------ ------------------------
INFO: Total time: 4.045s
INFO: End Memory: 6M / 218M
INFO: ------------------------------------------------ ------------------------
ERROR: Error while running SonarQube Scanner
ERROR: You must set the following mandatory properties for ‘ByteBank’: sonar.sources
ERROR:
ERROR: Run the SonarQube Scanner again using the -X switch to enable full debug logging.
WARN: Can not find ‘report-task.txt’ in workspace. Was SonarScanner successful?
ERROR: The SonarQube scanner came out with non-zero code: 1
Finished: FAILURE "

I imagine the problem is something in the parameters, in the configuration of the properties file, but I really do not know how to configure … = /