How to run single analysis for parallelism in CircleCI and get coverage report?

  • ALM used: GitHub
  • CI system used: Circle CI
  • Languages of the repository: Ruby
  • Private project

Hi everyone, I’m trying to set up SonarCloud analysis with CircleCI, but I’m running into two issues. I haven’t found a solution by searching past issues, and the documentation seems to be missing some details.

First, my repo’s specs run in parallel. I would like SonarCloud to run only once after the specs are complete, but it runs for each parallel instance.

Second, I would like a coverage report, and I have confirmed that it produces a coverage report using simplecov and uploads the artifacts (again, once for each parallel instance). However, when I look at my analysis, it claims that extra steps are still needed to set up coverage (indicating that the steps I took were insufficient).

Here is my CircleCI config, relevant portions only:

    # Omitted for brevity

    executor: rails
    parallelism: 4
    working_directory: ~/my_working_dir
      - setup-project # This is a custom command that handles checkout, npm, bundle, etc
      - run: |
          bundle exec rspec --profile 10 \
                            --format RspecJunitFormatter \
                            --out test_results/rspec.xml \
                            --format progress \
                            $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
      - store_test_results:
          path: test_results
      - store_artifacts:
          path: coverage
          # I can confirm that the coverage artifacts are uploaded, once for each parallel run
      - sonarcloud/scan 
        # This runs four times due to parallelism, but I would like it to only run once

    # Omitted for brevity

    when: << >> # This is the parameter that will be updated by the path-filtering orb
      - rspec:
          context: SonarCloud
      - db
      - rails-lint

And here is my



Is there any way for me to merge my parallel coverage reports and then run a sonar scan on the code base with the merged results?


Welcome to the community!

Let me start by saying I have no Circle CI experience. And…

From what I can tell, it’s doing what you told it to do.

Presumably, you need to move sonarcloud/scan into another command(?).

As for getting coverage included in your analysis, whether coverage reports are picked up implicitly - without you telling analysis where to look - is language-dependent. So it looks like you’ll need to put some SONARQUBE_SCANNER_PARAMS into your environment to pass your coverage report paths.


How about, is there an option for SonarCloud to add to an existing analysis rather than replace it?


There is not. That’s just not how analysis works.


There is not. That’s just not how analysis works.

I figured as much. Unfortunately I think that CircleCI and SonarCloud just don’t play nicely with each other when CircleCI is using parallelism. I think the solution is probably going to be on the CircleCI side of things, but they don’t make it easy to merge coverage analysis across parallel builds.

Ultimately the real solution is going to be for us to make our testing fast enough to not have to run them in parallel.

Regardless, thanks for your reply.

1 Like