Registry / devops / sonarqube-build-breaker

sonarqube-build-breaker

JSON →
library0.1.0jsnpmunverified

The `sonarqube-build-breaker` package is a Node.js module designed to enforce SonarQube quality gates within Continuous Integration (CI) pipelines. It integrates into the build process after `sonar-scanner` has completed its analysis and uploaded results to a SonarQube server. The module then queries the SonarQube server to check the project's quality gate status. If the quality gate is not passed (e.g., due to new critical issues, security vulnerabilities, or code coverage drops), the module will exit with a non-zero status code, effectively failing the CI build. This ensures that code quality standards are met before merging or deploying. Currently at version 0.1.0, its simple, focused functionality implies a stable yet low-cadence maintenance model. Its key differentiator is providing a programmatic way for Node.js projects to hard-fail builds based on SonarQube's quality gate decisions.

npm install sonarqube-build-breaker
INSTALL
IMPORT
SIG · SONARQUBE-BUILD-BR
S
sonarqube-build-breaker
devopsjavascriptv0.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sonar
const sonar = require('sonarqube-build-breaker');
import sonar from 'sonarqube-build-breaker';
This package is a CommonJS module. It exports an object containing the `checkQuality` function directly as `module.exports`.
checkQuality
const { checkQuality } = require('sonarqube-build-breaker');
import { checkQuality } from 'sonarqube-build-breaker';
While CommonJS, it's possible to destructure the `checkQuality` function directly from the `require` call if the module exports an object with `checkQuality` as a property. However, the README suggests importing the whole object and then calling its method.
Command Line Usage
node sonarBreaker.js
npm run sonarqube-build-breaker
The module is designed to be executed as a Node.js script in a CI environment, typically after `sonar-scanner` completes. It's not a standalone CLI tool installed globally.

Demonstrates how to integrate `sonarqube-build-breaker` into a CI pipeline to check SonarQube quality gates using environment variables.

const sonar = require('sonarqube-build-breaker'); // Best practice: use environment variables for sensitive data let token = process.env.SONAR_TOKEN ?? ''; let server = process.env.SONAR_SERVER ?? ''; let file = './.scannerwork/report-task.txt'; // This file is generated by sonar-scanner if (!token || !server) { console.error('SONAR_TOKEN and SONAR_SERVER environment variables must be set.'); process.exit(1); } sonar.checkQuality(server, file, token) .then(() => { console.log('SonarQube Quality Gate passed.'); process.exit(0); }) .catch(error => { console.error(`SonarQube Quality Gate failed: ${error.message}`); process.exit(1); }); // Example CI script snippet (e.g., in .travis.yml, github actions workflow, etc.) // npm install --save-dev sonarqube-build-breaker // # ... other build steps // sonar-scanner # Ensure sonar-scanner is installed and configured to run // node sonarBreaker.js
Debug
Known issues
gotchaThis module must be executed *after* `sonar-scanner` has successfully completed its analysis and uploaded results to the SonarQube server. It relies on the `report-task.txt` file generated by `sonar-scanner`.
fix
Ensure `sonar-scanner` is run and completes successfully before invoking `sonarqube-build-breaker` in your CI script.
affects: >=0.1.0
gotchaThe `report-task.txt` file path passed to `checkQuality` must be correct. This file is typically located in `./.scannerwork/` relative to where `sonar-scanner` was executed.
fix
Verify the exact location of `report-task.txt` in your CI environment and adjust the `file` parameter accordingly. For monorepos, pay extra attention to the working directory.
affects: >=0.1.0
gotchaSonarQube authentication relies on a valid token. It is strongly recommended to use environment variables (e.g., `process.env.SONAR_TOKEN`) rather than hardcoding tokens directly in your script.
fix
Configure your CI environment to securely provide `SONAR_TOKEN` and `SONAR_SERVER` as environment variables.
affects: >=0.1.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, open './.scannerwork/report-task.txt'
The `report-task.txt` file, which is required by `sonarqube-build-breaker`, was not found at the specified path. This typically means `sonar-scanner` did not run, failed, or generated the file in a different location.
fix
Verify that `sonar-scanner` executed successfully prior to `sonarqube-build-breaker` and check the actual path where `report-task.txt` is generated, then update the `file` parameter in your script.
TypeError: sonar.checkQuality is not a function
This error occurs if the `sonarqube-build-breaker` module was imported incorrectly, leading to `sonar` not being the expected object containing the `checkQuality` function.
fix
Ensure you are using the CommonJS `require` syntax: `const sonar = require('sonarqube-build-breaker');`.
SonarQube API call failed: 401 Unauthorized
The SonarQube token provided is invalid or lacks the necessary permissions to access the project's quality gate status on the SonarQube server.
fix
Double-check that the `SONAR_TOKEN` environment variable (or wherever you're providing the token) is correct and has sufficient permissions on your SonarQube instance.
SonarQube Quality Gate failed: Build failed due to quality gate conditions.
This is the intended behavior of the module when the SonarQube quality gate for the analyzed project is not met.
fix
Review the SonarQube analysis results for your project, address the identified code quality issues, and rerun the analysis.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
sonarqube-build-breaker — npm install sonarqube-build-breaker · libregistry