Jenkins SonarQube integration for c# code

Hi All,

I have installed jenkins locally and sonar locally and I am trying to configure jenkins pipeline with sonarqube, and have configure SonarQube server(Named: SonarScanServer) and scanner MSBuild 4.6.2.2108 (Named:MSBuild_Sonar_Scanner)

But i am getting error as below
/.jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/MSBuild_Sonar_Scanner/SonarQube.Scanner.MSBuild.exe: cannot execute binary file

I guess its due to permission issue, so its not executing shell cmd as scripted.
Kindly help me resolved it.

 stage('Build + SonarQube analysis') {
        
          steps {
                  script {
                 // requires SonarQube Scanner 2.8+
                       sqScannerMsBuildHome = tool 'MSBuild_Sonar_Scanner'
                     }
            withSonarQubeEnv('SonarScanServer') {
                  
                      // sh "${sqScannerMsBuildHome}/bin/sonar-scanner" (This cmd works but dont scan c#)
                       sh "${sqScannerMsBuildHome}/SonarQube.Scanner.MSBuild.exe begin /projectKey..."
                       sh 'MSBuild.exe /t:Rebuild'
                       sh "${sqScannerMsBuildHome}/SonarQube.Scanner.MSBuild.exe end"
 
                    }
            }
            
             stage("Quality Gate") {
               steps {
                timeout(time: 1, unit: 'HOURS') {
                    // Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
                    // true = set pipeline to UNSTABLE, false = don't
                    waitForQualityGate abortPipeline: true
                }
            }

Thanks,
Avinash

Hi Avinash,

Have you tried changing the permissions on the executable?

 
Ann

You’re trying to execute a sh command instead of a bat but it depends on your OS.

Your OS on jenkins is it windows or Linux?.

Yes I have checked with the permission on executable and running on MAC .
I am able to scan with by just appending mono to same cmd in terminal and its working.
But when i set Environment variable PATH for Mono cmd , the build process goes in loop as below log

Warning: JENKINS-41339 probably bogus
PATH=/Library/Frameworks/Mono.framework/Versions/5.18.1/Commands:$PATH; perhaps you meant to use ‘PATH+EXTRA=/something/bin’?
sh: touch: command not found
sh: sleep: command not found
sh: touch: command not found
sh: sleep: command not found
sh: touch: command not found
sh: sleep: command not found
sh: touch: command not found
sh: touch: command not found
sh: sleep: command not found
sh: mv: command not found

Hi @avinashk,

I’m not a Mac user, hence I might be wrong, but I think you have to use the export keyword:
export [existing_variable_name]=[new_value]:$[existing_variable_name]

You can find more details here: https://medium.com/@himanshuagarwal1395/setting-up-environment-variables-in-macos-sierra-f5978369b255

Costin