Configuring the scanner
The page explains how to set up the analysis parameters for the SonarScanner for NPM.
The analysis parameters are used to set up the project analysis. For more information, see General configuration guidelines.
Depending on your tool environment and strategy, and on the analysis parameter (global or not, must be securely passed or not), you may choose one or the other setup method described on this page.
Introduction to the analysis parameters setup
The SonarScanner for NPM reads or receives parameters from different sources:
It gets analysis parameters through its APIs.
It reads analysis parameters from
package.json.It reads analysis parameters from environment variables.
It reads parameters from the
sonar-project.propertiesfile.It gets the parameters that were set in the SonarQube Cloud UI.
Some parameters are assigned a default value.
The table below lists the different configuration methods in the order of priority in which the SonarScanner for NPM processes the corresponding parameters.
1
API parameters
Parameters can be provided to the scanner either through the JS code API or through the command line API.
2
Environment variables
Some parameters can be stored in environment variables on the CI/CD host.
4
Project configuration file
Parameters can be defined in the sonar-project.properties file stored in the project root directory.
3
package.json
The scanner reads some analysis parameters from fields of the package.json file.
5
Default values
Some parameters are assigned a default value. The parameters considered here are parameters that cannot be set in the UI.
6
UI
Parameters can be set in the UI for a given project.
Analysis parameters read from package.json
The SonarScanner for NPM parses the package.json file of the project to be analyzed and reads the value of the parameters below from the corresponding package.json field. For information about the listed analysis parameters, see Parameters not settable in the UI.
sonar.projectName
name
sonar.projectVersion
version
sonar.projectDescription
description
sonar.links.homepage
homepage
sonar.links.issue
bugs.url
sonar.links.scm
repository.url
In addition, specific values may be added to the parameters listed below if particular conditions are fulfilled.
sonar.exclusions
sonar.javascript.lcov.reportPaths
nyc.report-dir and jest.converageDirectory directories
If an lcov.info file is specified in the package.json fields nyc.report-dir and jest.converageDirectory
sonar.testExecutionReportPath
Xunit.xml file
If the package.json has declared the dependency mocha-sonarqube-reporter and the file xunit.xml exists in the project directory.
Providing analysis parameters through the scanner API
See Adding the analysis step to your build files or Starting the scanner from the command line with npx articles.
Setting analysis parameters in environment variables
You can use environment variables on the CI/CD host to define analysis parameters:
Some parameters can be defined through a dedicated environment variable. For example, the
sonar.regionproperty value can be defined through theSONAR_REGIONenvironment variable. See Parameters not settable in the UIto know which parameters can be set as environment variables.The
SONAR_SCANNER_JSON_PARAMSenvironment variable allows you to pass multiple analysis parameters in a single variable, encoded as JSON.
Example:
Setting analysis parameters in sonar-project.properties
See the Manual configuration article on the SonarScanner CLI page.
Setting analysis parameters in the SonarQube Cloud UI
You can set analysis parameters in the SonarQube Cloud UI for your project provided you have Administer permission for this project.
To set analysis parameters at the project level:
Open your project. See Retrieving projects for details.
Go to Administration > General Settings.
Related pages
Choosing your region [LINK]
Last updated
Was this helpful?

