Sonarcloud with bitbucket pipelines for IOS repo

  • Sonarcloud using Bitbucket pipelines.
  • CI system used Bitbucket Cloud
  • Languages of the repository: Swift
  • The SonarCloud project is private.
`Skipping cache upload for failed step`
`Searching for test report files in directories named [test-results, failsafe-reports, test-reports, TestResults, surefire-reports] down to a depth of 4`
`Finished scanning for test reports. Found 0 test report files.`
`Merged test suites, total number tests is 0, with 0 failures and 0 errors.`

Hey there.

I’m not sure what your question is :slight_smile:

I am getting this error while I am running the build. This is an IOS repository that I am working with Bitbucket pipelines.

Here is my pipelines:

image: gcc:10
clone:
  depth: full              # SonarCloud scanner needs the full history to assign issues properly
definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - sonar
        script:
          - export SONAR_SCANNER_VERSION=4.4.0.2170
          - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
          - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
          - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
          - export PATH=$SONAR_SCANNER_HOME/bin:$PATH
          - export COMPILE_DATABASE=./compile_commands.json
          - sonar-scanner -Dsonar.cfamily.compile-commands=$COMPILE_DATABASE
pipelines:                 # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
  branches:
    master:
      - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud
# sonar-project.properties
sonar.projectKey=
sonar.organization=
sonar.projectName=
sonar.sources=
sonar.tests=
sonar.sourceEncoding=UTF-8

Error:

`Skipping cache upload for failed step`
`Searching for test report files in directories named [test-results, failsafe-reports, test-reports, TestResults, surefire-reports] down to a depth of 4`
`Finished scanning for test reports. Found 0 test report files.`
`Merged test suites, total number tests is 0, with 0 failures and 0 errors.`

I am getting this error in the build.
pipelineLog-{664041fb-68fc-4aa0-b97a-33fb8130cc35}.txt (68.3 KB)

It looks like the compilation database can’t be found. What happens if you run

cat $COMPILE_DATABASE

before the sonar-scanner? do you see the contents?

Thank you for replying back immediately…

pipelineLog-{04c1b003-8a75-4d4c-9688-5370f6fa5963}.txt (68.6 KB)

image: gcc:10
clone:
  depth: full              # SonarCloud scanner needs the full history to assign issues properly
definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - sonar
        script:
          - export SONAR_SCANNER_VERSION=4.4.0.2170
          - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
          - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
          - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
          - export PATH=$SONAR_SCANNER_HOME/bin:$PATH
          - cat $COMPILE_DATABASE
          - sonar-scanner -Dsonar.cfamily.compile-commands=$COMPILE_DATABASE
pipelines:                 # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
  branches:
    master:
      - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

This is how you mentioned…?

+ cat $COMPILE_DATABASE

+ sonar-scanner -Dsonar.cfamily.compile-commands=$COMPILE_DATABASE

Since there’s no output of the cat, the file probably does not exist in a context where it can be read, hence why you receieve an error that the file does not exist.

When/How are you producing the compilation database?

I can’t share much of the details can you be more precise on it. Do i need to create an empty file as there are is no compile-commands.json file. There are no C++ , Obj C related code files and there are only swift files present in the repo.

Can i know how to fix this…?

image: gcc:10

clone:
  depth: full  # SonarCloud scanner needs the full history to assign issues properly

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build

  steps:
    - step: &build-test-sonarcloud
        name: Build, test, and analyze on SonarCloud
        caches:
          - sonar
        script:
          # Download and configure SonarScanner
          - export SONAR_SCANNER_VERSION=4.4.0.2170
          - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
          - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
          - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
          - export PATH=$SONAR_SCANNER_HOME/bin:$PATH

          # Run SonarScanner for Swift analysis with the existing Xcode project
          - sonar-scanner -Dsonar.language=swift -Dsonar.swift.workspace=UI.xcodeproj

pipelines:  # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
  branches:
    master:
      - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

How to solve it…Can you please reply immediately. Thank you very much.

Then… there’s no need to include sonar.cfamily.compile-commands. Why are you adding it, and what happens if you don’t?

Hi Colin! Thank you very much for your support. I resolved it by adding an empty compile-commands.json file.

 []

Since it didn’t have any C++ , Obj C related code files. And I have removed the
sonar.cfamily.compile-commands.

I have used this pipeline:

image: gcc:10
clone:
  depth: full              # SonarCloud scanner needs the full history to assign issues properly
definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - sonar
        script:
          - export SONAR_SCANNER_VERSION=4.4.0.2170
          - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
          - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
          - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
          - export PATH=$SONAR_SCANNER_HOME/bin:$PATH
          - cat $COMPILE_DATABASE
          - sonar-scanner -Dsonar.cfamily.compile-commands=$COMPILE_DATABASE
pipelines:                 # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
  branches:
    master:
      - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

And just added the empty json file and it worked well for me. Thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.