Hello,
I have a Project with a Frontand (Javascript) and a Backaned (C#). The normal SonarScanner runs without problems but gave me the Hint that I need the .Net Scanner to scan my C# Files.
I currently try to get the .Net Scanner of SonarQube running on my Jenkins but it feels like no matter what I do I can’t get it running.
My Jenkins is running on a Linux as a hint.
which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
- Sonarqube version: * Community Edition Version 9.5 (build 56709)
- SonarQube Scanner for Jenkins Version 2.14
→ Nomal Scanner: 4.7.0, .Net Scanner 5.7.2 Net Fwk 4.6
→ Manually installed the newest version
what are you trying to achieve
Analys commits to check for errors in my code
what have you tried so far to achieve this:
- Use the SonarScanner .Net Jenkins Plugin and the .Net Jenkins Plugin
→ Used the Jenkins “Freestyle” Project, selected “SonarScanner for MS - Beginn Analysis”, then a Build and then “SonarScanner for MS - EndAnalysis”
Sadly this resulted in Jenkins trying to acces a .exe File whis is not possible in Linux and gave me this error:
/var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScannerMS/SonarScanner.MSBuild.exe: 1: MZ����@���: not found
/var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScannerMS/SonarScanner.MSBuild.exe: 1: ��O�Ta�L�8: not found
/var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScannerMS/SonarScanner.MSBuild.exe: 21: ����0l
>� �@ ���.rsrcTa�n@@.reloc�v@B�H5 I *,~�
̈�0aos
rp�8%rp�(0s
o
rp�8%r-p�(1s
o
~e
o
~
o
�*0=�8%r5p�%r9p�(
+a�
(+,*Xa�i2�*0�-r=ps
z-r]ps
zQ~s
o!
a(: File name too long
/var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScannerMS/SonarScanner.MSBuild.exe: 23: Syntax error: newline unexpected (expecting ")")
ERROR: Execution of SonarScanner for MSBuild failed (exit code 2)
- When I tried to link to the .dll file through a scripted pipline (in the same path as I got from the error above) I still get an error:
+ dotnet /SonarScanner.MSBuild.dll begin /k:myKey
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet-/SonarScanner.MSBuild.dll does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
This seems to me that the path is wrong, but I don’t know which the right one whould be. So I tried something different
-
I installed the sonarscanner myself with the following command::
dotnet tool install --global dotnet-sonarscanner
→ The installation work without problems. The file is here. When I try to run the scanner I get this error (PS: I treid it with both “dotnet sonarscanner begin” and “dotnet-sonarscanner begin”, same problem):
+ dotnet-sonarscanner begin /k:sap_fehlertracking-db_AYHNNuMNuXqET0luRRRS
You must install .NET to run this application.
App: /home/jenkins/.dotnet/tools/dotnet-sonarscanner
Architecture: x64
App host version: 6.0.7
.NET location: Not found
Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed
Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=debian.11-x64&apphost_version=6.0.7
Here is my jenkinsfile pipeline script (Catch block is not properly working, even tho I get an error it still succeeds, it’s still a WIP)
stage('SonarQube Analysis') {
updateGitlabCommitStatus name: 'SonarQube Analysis', state: 'pending'
nodejs(nodeJSInstallationName: 'nodejs') {
sh 'node -v'
withSonarQubeEnv() {
env.PATH = "$PATH:/home/jenkins/.dotnet"
env.PATH = "$PATH:/home/jenkins/.dotnet/tools"
script {
try {
sh '''
dotnet sonarscanner begin /k:"MyKey"
dotnet build fehlertracking.sln
dotnet sonarscanner end
'''
updateGitlabCommitStatus name: 'SonarQube Analysis', state: 'success'
} catch (ex) {
updateGitlabCommitStatus name: 'SonarQube Analysis', state: 'failed'
}
}
}
}
}
If someone here could help me out what the problem is/ how I can fix it or get it running I whould really appreciate. The documentation on the page for Linux systems is sadly missing a lot of key infos (or I’m just to bad to read it)