SonarCloud Swift code coverage help

  • ALM used: GitHub
  • CI system used: Circle CI
  • Scanner command used when applicable (private details masked)
    description: "Sonarcloud scan"
      - run:
          command: |
            ./scripts/ output/*.xcresult > output/sonarcloud-coverage.xml
      - sonarcloud/scan

  • Languages of the repository: Swift
  • Error observed
/tmp/cache/scanner/sonar-scanner- line 66: /private/tmp/cache/scanner/sonar-scanner- cannot execute binary file
/tmp/cache/scanner/sonar-scanner- line 66: /private/tmp/cache/scanner/sonar-scanner- Undefined error: 0

Exited with code exit status 1
CircleCI received exit code 1
  • Steps to reproduce

Seems like from your tutorial that the Linux orb is the only official orb available for Circle CI. I’m really at a loss understanding your documentation as to how to get my code coverage results uploaded to Sonarcloud.

We were setup using automatic analysis but then read (Enriching Your Analysis | SonarCloud Docs) that code coverage features were available only with CI-Analysis, so we changed that and realized that the orb only supports Linux. I think that’s where we’re currently stuck.

  • Potential workaround


Can you provide the full log, starting from the analysis command?

Also, it appears that you’re converting your coverage report to the Generic Coverage report format and then attempting to import it as an llvm-cov show report. That’s not going to work. If you’re producing a Generic Coverage report, analysis needs to consume it as sonar.coverageReportPaths.


I don’t run the analysis command directly. Am I missing a step? I run tests and get a xcresult file that is then converted to the generic format. Should I run another type of analysis before scan?

Here is the full output from the sonarcloud scan step from CircleCI. It seems like it’s assuming this is a linux machine, not a macOS-based VM from Circle as needed for Swift development.

#!/bin/bash --login -o pipefail
set -e

if [[ ! -x "$SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/bin/sonar-scanner" ]]; then
  curl -Ol$VERSION-$
  unzip -qq -o sonar-scanner-cli-$VERSION-$ -d $SCANNER_DIRECTORY

chmod +x $SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/bin/sonar-scanner
chmod +x $SCANNER_DIRECTORY/sonar-scanner-$VERSION-$OS/jre/bin/java


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 41.1M  100 41.1M    0     0  74.8M      0 --:--:-- --:--:-- --:--:-- 75.8M
/tmp/cache/scanner/sonar-scanner- line 66: /private/tmp/cache/scanner/sonar-scanner- cannot execute binary file
/tmp/cache/scanner/sonar-scanner- line 66: /private/tmp/cache/scanner/sonar-scanner- Undefined error: 0

Exited with code exit status 1
CircleCI received exit code 1


Yeah, that looks like the problem. We only offer a Linux integration for CircleCI. Instead of using the orb, you’ll need to execute SonarScanner manually. There’s a path through the onboarding wizard that brings you to those instructions if you use “use another CI”

Regarding the the coverage report, I was looking at this:

You’re going to get a Generic Coverage report out of that, so you want to use the corresponding sonar.coverageReportPaths parameter to pass it in, not the sonar.swift.coverage.reportPaths parameter.


1 Like

Thank you, I’ll give that a shot.

1 Like

I had to move my file to, but after that it worked!

Any way to point the scanner to use a custom properties file with a different path?

1 Like


There’s not. (There used to be, but it was removed several years ago.)


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