I'm using sonarcloud-scan and sonarcloud-quality-gate, the last step fails

Template for a good new topic, formatted with Markdown:

  • ALM used: Bitbucket Cloud

  • CI system used: Bitbucket Cloud

  • Languages of the repository: Ruby

  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)

Sonarcloud-scan pipe passes and I can see the test coverege from the developer is above the threshold configured in the sonarcloud quality gate and profiles.

I can’t see why this is not working, I’ve tried many configurations and they all fail in the quality gate pipe. We have a paid plan up to date with enough lines of code available.


pipe: sonarsource/sonarcloud-quality-gate:0.1.4
9s
+ docker container run \
   --volume=/opt/atlassian/pipelines/agent/build:/opt/atlassian/pipelines/agent/build \
   --volume=/opt/atlassian/pipelines/agent/ssh:/opt/atlassian/pipelines/agent/ssh:ro \
   --volume=/opt/atlassian/pipelines/bin/docker:/usr/local/bin/docker:ro \
   --volume=/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes:/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes \
   --volume=/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/sonarsource/sonarcloud-quality-gate:/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/sonarsource/sonarcloud-quality-gate \
   --workdir=$(pwd) \
   --label=org.bitbucket.pipelines.system=true \
   --env=BITBUCKET_STEP_TRIGGERER_UUID="$BITBUCKET_STEP_TRIGGERER_UUID" \
   --env=BITBUCKET_REPO_FULL_NAME="$BITBUCKET_REPO_FULL_NAME" \
   --env=BITBUCKET_GIT_HTTP_ORIGIN="$BITBUCKET_GIT_HTTP_ORIGIN" \
   --env=BITBUCKET_PROJECT_UUID="$BITBUCKET_PROJECT_UUID" \
   --env=BITBUCKET_REPO_IS_PRIVATE="$BITBUCKET_REPO_IS_PRIVATE" \
   --env=BITBUCKET_WORKSPACE="$BITBUCKET_WORKSPACE" \
   --env=BITBUCKET_SSH_KEY_FILE="$BITBUCKET_SSH_KEY_FILE" \
   --env=BITBUCKET_PR_DESTINATION_COMMIT="$BITBUCKET_PR_DESTINATION_COMMIT" \
   --env=BITBUCKET_REPO_OWNER_UUID="$BITBUCKET_REPO_OWNER_UUID" \
   --env=BITBUCKET_BRANCH="$BITBUCKET_BRANCH" \
   --env=BITBUCKET_REPO_UUID="$BITBUCKET_REPO_UUID" \
   --env=BITBUCKET_PROJECT_KEY="$BITBUCKET_PROJECT_KEY" \
   --env=BITBUCKET_REPO_SLUG="$BITBUCKET_REPO_SLUG" \
   --env=CI="$CI" \
   --env=BITBUCKET_PR_ID="$BITBUCKET_PR_ID" \
   --env=BITBUCKET_REPO_OWNER="$BITBUCKET_REPO_OWNER" \
   --env=BITBUCKET_STEP_RUN_NUMBER="$BITBUCKET_STEP_RUN_NUMBER" \
   --env=BITBUCKET_BUILD_NUMBER="$BITBUCKET_BUILD_NUMBER" \
   --env=BITBUCKET_GIT_SSH_ORIGIN="$BITBUCKET_GIT_SSH_ORIGIN" \
   --env=BITBUCKET_PIPELINE_UUID="$BITBUCKET_PIPELINE_UUID" \
   --env=BITBUCKET_COMMIT="$BITBUCKET_COMMIT" \
   --env=BITBUCKET_PR_DESTINATION_BRANCH="$BITBUCKET_PR_DESTINATION_BRANCH" \
   --env=BITBUCKET_CLONE_DIR="$BITBUCKET_CLONE_DIR" \
   --env=PIPELINES_JWT_TOKEN="$PIPELINES_JWT_TOKEN" \
   --env=BITBUCKET_STEP_UUID="$BITBUCKET_STEP_UUID" \
   --env=BITBUCKET_DOCKER_HOST_INTERNAL="$BITBUCKET_DOCKER_HOST_INTERNAL" \
   --env=DOCKER_HOST="tcp://host.docker.internal:2375" \
   --env=BITBUCKET_PIPE_SHARED_STORAGE_DIR="/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes" \
   --env=BITBUCKET_PIPE_STORAGE_DIR="/opt/atlassian/pipelines/agent/build/.bitbucket/pipelines/generated/pipeline/pipes/sonarsource/sonarcloud-quality-gate" \
   --env=SONAR_TOKEN="${SONAR_TOKEN}" \
   --add-host="host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL" \
   sonarsource/sonarcloud-quality-gate:0.1.4
Unable to find image 'sonarsource/sonarcloud-quality-gate:0.1.4' locally
0.1.4: Pulling from sonarsource/sonarcloud-quality-gate
d121f8d1c412: Pulling fs layer
ca572574cc82: Pulling fs layer
2bec6349c99d: Pulling fs layer
087ac0b72728: Pulling fs layer
6ca52d7c92b3: Pulling fs layer
f8f3658cfe37: Pulling fs layer
44dfc5bf09c4: Pulling fs layer
4cd0692f4960: Pulling fs layer
087ac0b72728: Waiting
6ca52d7c92b3: Waiting
f8f3658cfe37: Waiting
44dfc5bf09c4: Waiting
4cd0692f4960: Waiting
2bec6349c99d: Verifying Checksum
2bec6349c99d: Download complete
ca572574cc82: Verifying Checksum
ca572574cc82: Download complete
087ac0b72728: Verifying Checksum
087ac0b72728: Download complete
f8f3658cfe37: Verifying Checksum
f8f3658cfe37: Download complete
6ca52d7c92b3: Verifying Checksum
6ca52d7c92b3: Download complete
d121f8d1c412: Verifying Checksum
d121f8d1c412: Download complete
44dfc5bf09c4: Download complete
4cd0692f4960: Verifying Checksum
4cd0692f4960: Download complete
d121f8d1c412: Pull complete
ca572574cc82: Pull complete
2bec6349c99d: Pull complete
087ac0b72728: Pull complete
6ca52d7c92b3: Pull complete
f8f3658cfe37: Pull complete
44dfc5bf09c4: Pull complete
4cd0692f4960: Pull complete
Digest: sha256:fefdf81312845d1773ec5dbb285f1628025f1496bda7a92e1d9f5f9994999a96
Status: Downloaded newer image for sonarsource/sonarcloud-quality-gate:0.1.4
✖ Quality Gate failed
- Coverage on New Code: 0.0 (is less than 60)

* Steps to reproduce
   - step: &sonarcloud
        name: Analyze on SonarCloud
        caches:
          - sonar
          - node  # Use the node cache
        artifacts:
          - coverage/**  
          - test-reports/**
        script:
          - pipe: sonarsource/sonarcloud-scan:2.0.0
            variables:
              EXTRA_ARGS: -Dproject.settings=\"./sonar-scanner.properties\"  # I also tried -Dproject.settings="./sonar-scanner.properties" but that doens't fix the issue either.
              SONAR_TOKEN: $SONAR_TOKEN
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.4
        services:
          - docker


 # I've also added the following as a separate step but that fails with the same error message in the build logs.

    - step: &check-quality-gate-sonarcloud
        name: Check the Quality Gate on SonarCloud
        script:
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.4

It looks like it is working – you’ve added a step in your pipeline to fail the build if the project’s Quality Gate fails… and the project’s Quality Gate is failing. Were you expecting something different?

Hi Colin, thank you for answering.

Yes, I’m expecting the same coverage as the tests that the developer created.

I’ve added a debugging step after the “bundle rspec exec” command.

ˋˋˋ
lcov --summary coverage/lcov/build.lcov<1s

1

+ lcov --summary coverage/lcov/build.lcov

2

Reading tracefile coverage/lcov/build.lcov

3

Summary coverage rate:

4

lines......: 61.3% (2910 of 4749 lines)

5

functions..: no data found

6

branches...: no data found

ˋˋˋ

From the output of the debugging step you can see that there is 61.3% of code coverage but the sonarcloud-scan and the quality gate pipe says that there is 0% coverage.

Sonarcloud-scan pipe can generate a report. Here is the output after setting sonar.verbose=true

ˋˋˋ
04.499 INFO: Rule | Time (ms) | Relative

3450

22:55:04.499 INFO: :-----------------------------|----------:|--------:

3451

22:55:04.499 INFO: internal-cognitive-complexity | 1.475 | 57.6%

3452

22:55:04.499 INFO: internal-symbol-highlighting | 1.086 | 42.4%

3453

22:55:04.541 DEBUG: The worker thread exited with code 0

3454

22:55:04.544 DEBUG: The bridge server shut down

3455

22:55:04.545 INFO: Rule | Time (ms) | Relative

3456

22:55:04.545 INFO: :----|----------:|--------:

3457

22:55:05.356 INFO: Analysis total time: 36.295 s

3458

22:55:05.357 INFO: ------------------------------------------------------------------------

3459

22:55:05.357 INFO: EXECUTION SUCCESS

3460

22:55:05.357 INFO: ------------------------------------------------------------------------

3461

22:55:05.357 INFO: Total time: 40.690s

3462

22:55:05.548 INFO: Final Memory: 44M/195M

3463

22:55:05.548 INFO: ------------------------------------------------------------------------

3464

22:55:05.558 DEBUG: Cleanup org.eclipse.jgit.util.FS$FileStoreAttributes$Lambda$288/0x00007f0b612f9160@1128620c during JVM shutdown

3465

✔ SonarCloud analysis was successful.
ˋˋˋ

Not sure if it helps but here is my bitbucket-pipeplines.yaml file



image: ruby:2.7.8

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

definitions:
  services:
    postgres:
      image: postgres:11.5
      environment:
        POSTGRES_DB: "xxxx"
        POSTGRES_USER: "xxxxx"
        POSTGRES_PASSWORD: "xxxx"
  caches:
#    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
    sonar: /opt/sonar-scanner/.sonar
    node: ~/.npm  # Define the node cache
    bundler:
      key:
        files:
          - Gemfile.lock
      path: vendor/bundle


  steps:
    - step: &lint
        name: Lint code
        script:
          - pipe: atlassian/git-secrets-scan:1.5.1
          - apt-get update
          - apt-get install -y nodejs
          - ruby -wc **/*.rb

    - step: &snyk-scan
        name: Snyk Security Scan
        script:
          - pipe: snyk/snyk-scan:1.0.1
            variables:
              SNYK_TOKEN: $SNYK_TOKEN
              LANGUAGE: "ruby" # Required unless SNYK_TEST_JSON_INPUT is set
              DONT_BREAK_BUILD: "true"
              EXTRA_ARGS:  "--all-projects --debug --project-tags=plataforma"
              SEVERITY_THRESHOLD: "high"

    - step: &snyk-scan-master
        name: Snyk Security Scan
        script:
          - pipe: snyk/snyk-scan:1.0.1
            variables:
              SNYK_TOKEN: $SNYK_TOKEN
              LANGUAGE: "ruby" # Required unless SNYK_TEST_JSON_INPUT is set
              DONT_BREAK_BUILD: "false"
              EXTRA_ARGS:  "--all-projects --debug"
              SEVERITY_THRESHOLD: "high"

    - step: &install-dependencies
        name: Install dependencies and setup database
        services:
          - postgres
        caches:
          - bundler
          - node
          - sonar
        script:
          - apt-get update -qq && apt-get install -y nodejs postgresql-client wkhtmltopdf libxml2-utils npm lcov
          - npm install -g lcov-summary
          - bundle install --path vendor/bundle
          - RAILS_ENV=test bundle exec rails db:create
          - psql -h localhost -U  -d  -c "CREATE USER postgres WITH SUPERUSER PASSWORD '';"
          - psql -h localhost -U  -d  -c "CREATE USER ricardoborges WITH SUPERUSER PASSWORD '';"
          - psql -h localhost -U  -d  -c "CREATE USER rdsadmin WITH SUPERUSER PASSWORD '';"
          - psql -h localhost -U  -d  -c "CREATE USER andre WITH SUPERUSER PASSWORD '';"
          - psql -h localhost -U  -d  -c "CREATE USER carlosbrida WITH SUPERUSER PASSWORD '';"
          - pg_restore -U  -h localhost -p 5432 -d  ./sql/xxx.tar
          - RAILS_ENV=test bundle exec rails db:migrate
          - mkdir -p test-reports/rspec
          - bundle exec rspec
          - ls -la vendor/bundle/
          - ls -la test-reports/rspec/
          - xmllint --noout test-reports/rspec/results.xml
          - echo "Coverage directory contents:"
          - ls -la coverage/
          - cat coverage/lcov/build.lcov 
          - lcov --summary coverage/lcov/build.lcov
        artifacts:
          - vendor/bundle
          - ./sql/xxx.tar
          - coverage/lcov/build.lcov
          - coverage/**
          - coverage/rspec.html
          - coverage/index.html
          - test-reports/**

    - step: &sonarcloud
        name: Analyze on SonarCloud
        caches:
          - sonar
          - node  # Use the node cache
        artifacts:
          - coverage/**  # Referenciar os artifacts de cobertura
          - test-reports/**
        script:
          - pipe: sonarsource/sonarcloud-scan:2.0.0
            variables:
              EXTRA_ARGS: -Dproject.settings=\"./sonar-scanner.properties\"
              SONAR_TOKEN: $SONAR_TOKEN
        services:
          - docker
          
    - step: &check-quality-gate-sonarcloud
        name: Check the Quality Gate on SonarCloud
        script:
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.6

    - step: &trivy-scan
        name: Trivy Security Scan
        image: docker:stable  # Docker-enabled image
        services:
          - docker
        script:
          - apk add --no-cache curl
          - curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
          - IMAGE_NAME=$(grep '^FROM ' ./devops/docker/production/Dockerfile | head -1 | awk '{print $2}')
          - WORKDIR=$(grep '^WORKDIR ' ./devops/docker/production/Dockerfile | awk '{print $2}' | tail -1)
          - echo "Docker Image $IMAGE_NAME"
          - echo "Workdir $WORKDIR"
          - echo "IMAGE_NAME=$IMAGE_NAME" > image_name.env
          - echo "WORKDIR=$WORKDIR" >> image_name.env
          - source image_name.env
          - echo "Pulling Docker Image $IMAGE_NAME"
          - docker pull $IMAGE_NAME
          - echo "Running Trivy Scan"
          - trivy image  --exit-code 1 --format table --severity HIGH,CRITICAL $IMAGE_NAME | tee trivy-report.txt
          - cat trivy-report.txt  # Display the contents of the TXT report for debugging
        artifacts:
          - trivy-report.txt

pipelines:
  branches:
    master:
      - step: *lint
      - step: *snyk-scan-master
      - step: *install-dependencies
      - step: *sonarcloud
#      - step: *check-quality-gate-sonarcloud
      - step: *trivy-scan

  pull-requests:
    '**':
      - step: *lint
#      - step: *snyk-scan
      - step: *install-dependencies
      - step: *sonarcloud
#      - step: *check-quality-gate-sonarcloud
      - step: *trivy-scan

The most important thing will be making sure you’re passing your test coverage reports to the right analysis parameter (sonar.ruby.coverage.reportPaths). That coverage report will also need to be in the correct format:

Comma-delimited list of paths to SimpleCov report files generated with the JSON formatter (available from SimpleCov 0.20). For SimpleCov versions before 0.18, you can provide .resultset.json report files (though we recommend updating to 0.20 and using the JSON formatter). Paths may be absolute or relative to the project root.

I’m assuming Ruby is the only language at play here, but if not, you can consult the same documentation for other languages.

The analysis logs will help you figure out if you have any issues importing these reports.

Thank you for your reply Colin,

Yes we’re only using Ruby.

Here is how I’m passing the coverage path in sonar-scanner.properties. (I’ve ommited some sensitive parts in the file).

# Coverage report paths
sonar.ruby.coverage.reportPaths=coverage/.resultset.json,coverage/coverage.json,coverage/lcov/build.lcov
sonar.junit.reportPaths=test-reports/rspec/results.xml
# Specify the language (not necessary if using the default multi-language analyzer)
sonar.language=ruby 
# Specify the test directories
sonar.tests=spec
sonar.test.inclusions=spec/**/*.rb
sonar.verbose=true

I shared this discussion with the developer and he added the following code to the rails_helper.rb file

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
  SimpleCov::Formatter::JSONFormatter,
  SimpleCov::Formatter::HTMLFormatter,
  SimpleCov::Formatter::LcovFormatter
])

SimpleCov.start 'rails' do
  add_filter '/bin/'
  add_filter '/config/'
  add_filter '/db/'
  add_filter '/spec/'
  add_filter '/app/models/dialer.rb'
  add_filter 'app/models/user.rb'
  add_filter 'app/models/application_record.rb'
  coverage_dir 'coverage'
end

SimpleCov.minimum_coverage 60

Checking the sonar-scan step in the pipelines log, I see:

17:32:11.370 WARN: Importing SimpleCov resultset JSON will not be supported from simplecov 18.0. Consider using the JSON formatter, available from SimpleCov 20.0
17:32:11.370 ERROR: Cannot read coverage report file, expecting standard SimpleCov JSON formatter output: 'coverage/.resultset.json'
java.lang.ClassCastException: class org.sonarsource.analyzer.commons.internal.json.simple.JSONObject cannot be cast to class org.sonarsource.analyzer.commons.internal.json.simple.JSONArray (org.sonarsource.analyzer.commons.internal.json.simple.JSONObject and org.sonarsource.analyzer.commons.internal.json.simple.JSONArray are in unnamed module of loader org.sonar.classloader.ClassRealm @8bd86c8)
	at java.base/java.util.HashMap.forEach(HashMap.java:1421)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.mergeFrameworkCoveragesFromResultSet(SimpleCovSensor.java:136)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.lambda$mergeFileCoverages$1(SimpleCovSensor.java:123)
	at java.base/java.util.HashMap.forEach(HashMap.java:1421)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.mergeFileCoverages(SimpleCovSensor.java:116)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.safeReadCoverageReport(SimpleCovSensor.java:82)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.lambda$execute$0(SimpleCovSensor.java:71)
	at java.base/java.util.HashMap.forEach(HashMap.java:1421)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.execute(SimpleCovSensor.java:71)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:62)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:48)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:66)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:48)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:192)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:188)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:159)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.ScannerContainer.doAfterStart(ScannerContainer.java:399)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:131)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
	at org.sonarsource.scanner.cli.Main.main(Main.java:62)

I’m still getting the error in the Quality Gate step:

✖ Quality Gate failed
- Coverage on New Code: 0.0 (is less than 60)

Hey there.

First things first, it looks like you’re chucking a lot of coverage files at sonar.ruby.coverage.reportPaths.

It’s important that you only pass valid ones, in the right format. That will depend on what version of SimpleCov you’re using. Assuming you’re using the latest version (or any version above 0.20), you should be be looking for a JSON file that isn’t a resultset file.

So try adjusting sonar.ruby.coverage.reportPath to only include the coverage/coverage.json file you mentioned.

Hi Colin!

I tried following your instructions but I’m still getting the same error, 0 coverage.

Are you still getting this error?

Or have the logs around the import of coverage changed?

Yes I still see the same error:

22:37:25.415 INFO: 47/47 source files have been analyzed
22:37:25.416 INFO: Sensor Ruby Sensor [ruby] (done) | time=7254ms
22:37:25.416 INFO: Sensor SimpleCov Sensor for Ruby coverage [ruby]
22:37:25.438 ERROR: Cannot read coverage report file, expecting standard SimpleCov JSON formatter output: 'coverage/coverage.json'
java.lang.ClassCastException: class java.lang.String cannot be cast to class org.sonarsource.analyzer.commons.internal.json.simple.JSONObject (java.lang.String is in module java.base of loader 'bootstrap'; org.sonarsource.analyzer.commons.internal.json.simple.JSONObject is in unnamed module of loader org.sonar.classloader.ClassRealm @489091bd)
	at java.base/java.util.HashMap.forEach(HashMap.java:1421)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.mergeFileCoverages(SimpleCovSensor.java:116)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.safeReadCoverageReport(SimpleCovSensor.java:82)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.lambda$execute$0(SimpleCovSensor.java:71)
	at java.base/java.util.HashMap.forEach(HashMap.java:1421)
	at org.sonarsource.ruby.plugin.SimpleCovSensor.execute(SimpleCovSensor.java:71)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:63)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:48)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:66)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:48)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:192)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:188)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:159)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.ScannerContainer.doAfterStart(ScannerContainer.java:399)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:131)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:126)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
	at org.sonarsource.scanner.cli.Main.main(Main.java:62)
22:37:25.439 INFO: Sensor SimpleCov Sensor for Ruby coverage [ruby] (done) | time=23ms

Can you share your coverage/coverage.json file here?

Here is the coverage report
coverage.json (64.6 KB)

I think the issue might be related to Quality Gate step not being able to open or read the artifact generated by the previous step.

Hey there.

The scanner is expecting a file in this format

I’m not sure how you’re getting the JSON file you’re passing to the scanner, but hopefully this example helps you generate it in the right format!

Thank you Colin,

I let the developer know and he’s going to test your suggestion. Thanks a lot

Just closing this thread, basically, it was about switching and using simplecov_json_formatter instead of simplecov-json.
Because simplecov-json was generating the old format.
And with this other one, it generates in the format that Sonar recognizes.
And in the sonar-scanner.properties, we added the same folders and files that are being used to generate the coverage.

So thanks a lot for your help Colin