Gathering detailed insights and metrics for sonarqube-scanner
Gathering detailed insights and metrics for sonarqube-scanner
Gathering detailed insights and metrics for sonarqube-scanner
Gathering detailed insights and metrics for sonarqube-scanner
npm install sonarqube-scanner
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
44 Stars
345 Commits
15 Forks
2 Watching
5 Branches
14 Contributors
Updated on 21 Nov 2024
TypeScript (90.84%)
JavaScript (7.24%)
Shell (0.91%)
Java (0.82%)
Dockerfile (0.13%)
Starlark (0.05%)
Cumulative downloads
Total Downloads
Last day
0.6%
91,943
Compared to previous day
Last week
1.8%
461,773
Compared to previous week
Last month
8.9%
1,945,222
Compared to previous month
Last year
25%
20,736,655
Compared to previous year
12
sonarqube-scanner
makes it very easy to trigger SonarQube Server
and Cloud analyses on a JavaScript code base, without needing
to install any specific tool or (Java) runtime.
This module is analyzed on SonarQube Cloud.
This is the documentation for v4. If you are using v3, refer to the v3 documentation.
Prerequisite: Node v18+ (for v4 and above)
Prerequisite: Node v16+ (for v3, otherwise use sonarqube-scanner v2.9.1)
This package is available on npm as: sonarqube-scanner
To add code analysis to your build files, simply add the package to your project dev dependencies:
1npm install -D sonarqube-scanner
To install the scanner globally and be able to run analyses on the command line:
1npm install -g sonarqube-scanner
Prerequisite: you've installed the package as a dev dependency.
The following example shows how to run an analysis on a JavaScript project, and pushing the results to a SonarQube instance:
1const scanner = require('sonarqube-scanner').default; 2 3scanner( 4 { 5 serverUrl: 'https://sonarqube.mycompany.com', 6 token: '019d1e2e04eefdcd0caee1468f39a45e69d33d3f', 7 options: { 8 'sonar.projectName': 'My App', 9 'sonar.projectDescription': 'Description for "My App" project...', 10 'sonar.sources': 'src', 11 'sonar.tests': 'test', 12 }, 13 }, 14 error => { 15 if (error) { 16 console.error(error); 17 } 18 process.exit(); 19 }, 20);
Syntax: sonarqube-scanner ( parameters
, [callback
] )
Arguments
parameters
Map
serverUrl
String (optional) The URL of the SonarQube Server or Cloud host. Defaults to https://sonarcloud.iotoken
String (optional) The token used to connect to the SonarQube Server v10+ or SonarQube Cloud. Empty by default.options
Map (optional) Used to pass extra parameters for the analysis. See the official documentation for more details.callback
Function (optional)
Callback (the execution of the analysis is asynchronous).Prerequisite: you've installed the package globally.
If you want to run an analysis without having to configure anything in the first place, simply run the sonar-scanner
command. The following
example assumes that you have installed SonarQube Server locally:
cd my-project
sonar-scanner
Specifying properties/settings
If there's a package.json
file in the folder, it will be read to feed the analysis with basic information (like project name or version)
If there's a sonar-project.properties
file in the folder, it will behave like the original SonarScanner
Additional analysis parameters can be passed on the command line using the standard -Dsonar.xxx=yyy
syntax
Example:
sonar-scanner -Dsonar.host.url=https://myserver.com -Dsonar.token=019d1e2e04e
To run analyses without explicitly installing the scanner, run the following command instead:
1npx sonarqube-scanner
Similar to the above, you can specify analysis properties and settings using either a package.json
file, a sonar-project.properties
file, or command line arguments.
You can install manually the standard SonarScanner, which requires to have a Java Runtime Environment available too (Java 8+).
It is important to make sure that the SonarScanner $install_directory/bin
location is added to the system $PATH
environment variable. This will ensure that sonar-scanner
command will be resolved by the customScanner, and prevent the error:
1Error: Local install of SonarScanner not found. 2 at getLocalSonarScannerExecutable (<project_dir>/node_modules/sonarqube-scanner/src/sonar-scanner-executable.js:153:11) 3 at scanUsingCustomScanner (<project_dir>/node_modules/sonarqube-scanner/src/index.js:52:3) 4...
Once local installation is done, you can replace the 2nd line of the example:
1var scanner = require('sonarqube-scanner').customScanner;
You are probably relying on Alpine for your Docker image, and Alpine does not include glibc by default. It needs to be installed manually.
Thanks to Philipp Eschenbach for troubleshooting this on issue #59.
By default, the scanner binaries are downloaded from https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/
.
To use a custom mirror, set $SONAR_SCANNER_MIRROR
. Or download precise version with $SONAR_SCANNER_VERSION
Example:
1export SONAR_SCANNER_MIRROR=https://npm.taobao.org/mirrors/sonar-scanner/ 2export SONAR_SCANNER_VERSION=3.2.0.1227
or alternatively set variable in .npmrc
sonar_scanner_mirror=https://npm.taobao.org/mirrors/sonar-scanner/
sonar_scanner_version=3.2.0.1227
For mirrors using Basic HTTP authentication (e.g. Sonatype Nexus 3 raw-proxy
, Artifactory with artifactory-cache-proxy
), simply specify the username and password
as part of the URL:
1export SONAR_SCANNER_MIRROR=https://username:password@repo.example.com/mirrors/sonar-scanner/
Proxy authentication is supported as well, see below.
By default, the scanner binaries are cached into $HOME/.sonar/native-sonar-scanner
folder.
To use a custom cache folder instead of $HOME
, set $SONAR_BINARY_CACHE
.
Example:
1export SONAR_BINARY_CACHE=/Users/myaccount/cache
or alternatively set variable in .npmrc
sonar_binary_cache=/Users/myaccount/cache
In order to be able to download binaries when you're behind a proxy it will be enough to set the http_proxy
or https_proxy
environment variable. Both support proxies using plain HTTP or HTTPS.
Example:
1export http_proxy=http://mycompanyproxy.com:PORT 2export https_proxy=http://mycompanyproxy.com:PORT 3 4export http_proxy=https://encryptedcompanyproxy.com:PORT 5export https_proxy=https://encryptedcompanyproxy.com:PORT
Behind authenticated proxy:
1export http_proxy=http://user:password@mycompanyproxy.com:PORT 2export https_proxy=http://user:password@mycompanyproxy.com:PORT 3 4export http_proxy=https://user:password@encryptedcompanyproxy.com:PORT 5export https_proxy=https://user:password@encryptedcompanyproxy.com:PORT
sonarqube-scanner
is licensed under the LGPL v3 License.
No vulnerabilities found.
No security vulnerabilities found.