Sonar coverage always 0%, bitbucket pipelines

I’m actually working on a React project using Bitbucket pipelines and sonarCloud to coverage code for this project.

Running sonar scan work fine

step: &step-sonar-scan
        size: 2x
        name: Analyze on SonarCloud
          - docker
          - docker
          - sonar
          - pipe: sonarsource/sonarcloud-scan:1.2.2
              SONAR_TOKEN: ${SONAR_TOKEN}
              EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**/__test__/**, **.test.js, **/*.spec.js" -Dsonar.javascript.lcov.reportPaths=coverage/'

But the quality gate didn’t show me the coverage code %.

step: &step-sonar-quality-gate
        trigger: 'manual'  # Could be reset to default state automatic
        name: Sonar Quality Gate
          - docker
          - docker
          - node # added
          - sonar
          - yarn test --coverage --watchAll=false --cache
          - pipe: sonarsource/sonarcloud-quality-gate:0.1.4

Locally, the cmd yarn test --coverage --watchAll=false --cache show coverage code equal to 86%

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 86.57 85 81.82 91.53
-------------------------------------------- ------------- --------------- -------------- ------------ ----------------------------

at sonar coverage it still always 0%

Could anyone please tell me if I made a mistake, or what am I missing?

Hey there.

You will need to make sure that this command runs before the sonarsource/sonarcloud-scan

yarn test --coverage --watchAll=false --cache

All of the analysis happens with the sonarsource/sonarcloud-scan pipe, while sonarsource/sonarcloud-quality-gate just polls for the Quality Gate that gets calculated after analysis is sent to SonarCloud.

1 Like

Thank you for your help
after changing the order, it works.
I have a question, is necessary to give the token to the quality gate pipe like this

          - pipe: sonarsource/sonarcloud-quality-gate:0.1.4
**              SONAR_TOKEN: ${SONAR_TOKEN}**

or the quality gate don’t need it ?

If SONAR_TOKEN is defined for your repository, there’s no need to include it in the bitbucket-pipelines.yml file.

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