We are using SonarQube version 5.2 and it is set up with jenkins to report the code coverage on SonarQube server currently only java code coverage is in place on sonarQube and now we are aiming to Fail the jenkins build if the project fails the quality gate and also Is it possible to integrate the jasmine test for javascript with SonarQube and how to acheive it
Asked
Active
Viewed 4,349 times
1 Answers
0
To make build success depend on quality measures, you can add a threshold into your jasmine karma testing.
In you karma.conf.js you may add:
coverageIstanbulReporter: { reports: [ 'html', 'lcovonly', 'text-summary', 'cobertura' ], fixWebpackSourcePaths: true, thresholds: { statements: 100, lines: 100, branches: 100, functions: 100 } },
This makes ng test --watch=false --code-coverage
fail if the coverage is less than 100%
you can of course change the threshold to your team needs.
Code style can be checked with
ng lint
using tslintMake SonarQube check your source code by adding
sonar-project.properties
to the root foldersonar.projectKey=YOUR_PROJECT_KEY sonar.projectName=YOUR_PROJECT_NAME sonar.projectVersion=YOUR_VERSION sonar.sources=src sonar.exclusions=**/node_modules/** sonar.tests=src/app sonar.test.inclusions=**/*.spec.ts sonar.sourceEncoding=UTF-8 sonar.ts.tslintconfigpath=tslint.json sonar.typescript.lcov.reportPaths=coverage/lcov.info
In your CI config you need to ensure that you are executing ng test --code-coverage
, tslint
and you need to activate SonarQube.
happy coding

Royalsmed
- 212
- 1
- 4
- 16
-
i tried adding the thresholds object in karma.conf file with value 100. And my current code coverage is way below 100. But still it doesnt fail, but rather shows success. Any pointers on how to fix this ? – Sagar Agrawal Mar 24 '21 at 11:44
-
@SagarAgrawal I noticed that long time ago. Angular/cli doesn't fail the test task if code coverage is below threshold (I believe starting from NG 6). It got fixed then broken again but I think it is finally working in latest NG version (not sure tho).... I ended up using my own script to check the coverage and exit with non-zero code manually otherwise. Basically you need a nodejs script to read the coverage html report and parse values and check if they match your expectation. I don't recommend this approach tho, best is to use the platform to avoid doing extra work – Royalsmed Mar 25 '21 at 12:45