sonar-scanner-npm
sonar-scanner-npm copied to clipboard
unable to use .npmrc download from mirrors values. returns undefined and set to base url
I am trying to set **To use a custom mirror, set $SONAR_SCANNER_MIRROR. Or download precise version with $SONAR_SCANNER_VERSION
Example: or alternatively set variable in .npmrc sonar_scanner_mirror=https://npm.taobao.org/mirrors/sonar-scanner/ sonar_scanner_version=3.2.0.1227** from https://github.com/bellingard/sonar-scanner-npm
I have a project at https://github.com/vasu512/sonar-scanner-vasu/tree/master/sonar-scanner and when I run npx sonar-scanner, the .npmrc values are not being used at and the base url is only set. the .npmrc values are returned as undefined. I have added logger statments in the node_modules/sonarqube-scanner/dist/sonarqube-scanner-executable.js file.
Steps to reproduce
- clone https://github.com/vasu512/sonar-scanner-vasu/tree/master/sonar-scanner
- cd sonar-scanner
- run
npx sonar-scannerOutput
npx sonar-scanner
[16:02:44] Starting SonarQube analysis...
[16:02:44] Getting info from "package.json" file
[16:02:44] **.npmrc setting: undefined**
[16:02:44] **Base value which is set: 4.3.0.2102**
[16:02:44] Checking if executable exists: C:\Users\srmuppal\.sonar\native-sonar-scanner\sonar-scanner-4.3.0.2102-windows\bin\sonar-scanner.bat
[16:02:44] Could not find executable in "C:\Users\srmuppal\.sonar\native-sonar-scanner".
[16:02:44] Proceed with download of the platform binaries for SonarQube Scanner...
[16:02:44] Creating C:\Users\srmuppal\.sonar\native-sonar-scanner
[16:02:44] **Base URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/**
[16:02:44] **.npmrc value: undefined**
[16:02:44] Downloading from https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.3.0.2102-windows.zip
[16:02:44] (executable will be saved in cache folder: C:\Users\srmuppal\.sonar\native-sonar-scanner)
I extract code snippet from sonar-scanner-executable.js
var baseUrl = process.env.SONAR_SCANNER_MIRROR || process.env.npm_config_sonar_scanner_mirror || SONAR_SCANNER_MIRROR
You can see the value of sonar_scanner_mirror in .npmrc file is extracted from process.env.npm_config_sonar_scanner_mirror and process.env.npm_config* is only available for the script using npm command. So you can wrap sonar scan task inside npm task by modifying package.json file
...
"scripts": {
"sonar:scan": "sonar-scanner"
}
...
Then run npm run sonar:scan should work.
Hey guys, would like to submit a PR for this? Either documentation or a small change?
Hello again @vasu512 and @lhtrang,
Thanks for bringing this up. There seem to be multiple people with this issue, see:
- #165
I'll close this for now to avoid duplicates. Please feel free to reopen if you have something more to contribute. Thanks!