Sonar Scanner failed to scan the Objective-c code

Currently, I am facing below error to scan Objective-c and for build configuration also using compilation database. Here is my sonar-scanner.properties:

#----- Default SonarQube server
sonar.host.url=http://localhost:9000/
sonar.projectKey=AppTest
sonar.projectName=AppTest
sonar.projectVersion=1.0
sonar.sources=.
sonar.cfamily.compile-commands=compile_commands.json
sonar.login=admin
sonar.password=12345678

This is SonarQube version:

  • Developer Edition
  • Version 9.8 (build 63668)

Hey there.

Are you running the analysis on the same machine where the compilation database was generated?

Yes, I am, but for analysis I also tried to different machine between Jenkins and SonarQube server. For Compilation Database also generated in the root project. Here is a compile_command.json.

Hey there.

Citing this excellent blog article if some files are generated during the build and referenced (directly or not) by the compilation database, we will need them during analysis. This means that even if you configure analysis with a compilation database, enough of the build should be run that the generated files are present for analysis (or are retrieved from some cache),

Hi Colin,

for compilation database was generated only first time it’s not during the build, so you mean that need to generate every time after finished build?

Even when a compilation database is being used (and not the build wrapper), the analysis must still take place in the same environment as the build. It is not possible, for example, to check into source control a compilation database generated on a developer’s local machine and expect that analysis will be successful in a CI environment.

The expectation is that some build will have taken place that generates the compilation database which is immediately used for analysis (whether’s it’s a full, clean build, or an incremental build).

Currently, I’m using connection Jenkins to SonarQube, and then it always got unable to execute SonarScanner analysis and Unexpected response code for CONNECT: 503.

Here is my Jenkins file.

pipeline {
agent { label ‘mac-Mini-host’ }
stages {
stage(‘Install Pods’) {
steps {
script {
“export LANG=en_US.UTF-8”
“/usr/local/bin/pod install”
}
}
}
stage(‘generate compile_command.json’) {
steps {
script {
try {
“chmod +x generate-xcode-compilation-database.sh”
“./generate-xcode-compilation-database.sh xcodebuild clean build -workspace sim-registration.xcworkspace -destination generic/platform=iOS -scheme sim-registration -configuration Debug”
“cd CompilationDatabase”
“sed -e *.json > compile_commands.json”
} catch(error) {
“cd CompilationDatabase”
“sed -e *.json > compile_commands.json”
}
}
}
}
stage(‘SonarQube Analysis’) {
steps {
script {
def scannerHome = tool ‘SonarScanner’;
withSonarQubeEnv() {
sh "${scannerHome}/bin/sonar-scanner
-Dsonar.projectKey=AppTest
-Dsonar.projectName=AppTest
-Dsonar.projectVersion=1.0
-Dsonar.sourceEncoding=UTF-8
-Dsonar.host.url=http://localhost:9000
-Dsonar.cfamily.compile-commands=CompilationDatabase/compile_commands.json
-Dsonar.login=userTest
-Dsonar.password:12345678”
}
}
}
}
}

It looks like the logs show a different connection being tried than localhost:9000 – which SonarQube URL are you really trying to connect to?

Nope, I just give you the sample host URL, but the correct URL like above screenshot.

Then it seems like there’s some connectivity issue between your build server and your SonarQube instance. I would suggest adding a simple curl to your pipeline to see if you receive the same error code. As your SonarQube server is being served over HTTPS, this is likely being returned by the proxy sitting in front of your SonarQube server.

Yes, I used to try simple curl to see that and reply good and proxy already added.

In that case, I would check the logs of your reverse proxy to understand why it’s returning a 503.