I install sonar-scanner via docker on my mac
(https://hub.docker.com/r/sonarsource/sonar-scanner-cli) and I getting the error "You must define the following mandatory properties for 'Unknown': sonar.projectKey".
I have done the following:
1: add a sonar-scanner.properties file in the root of JS project
# Required metadata
sonar.projectKey=my-app
sonar.projectName=Franchise
sonar.projectVersion=1.0
# Comma-separated paths to directories with sources (required)
sonar.sources=server/app.js,pages,components
2 Installed docker and the scanner
Here my docker command
docker run --rm -e SONAR_HOST_URL="https://sonarqube.comp.com/" -e SONAR.PROJECTKEY="my-app" -v "/git/franchises" sonarsource/sonar-scanner-cli
Can please let me know how to pass the information correctly.
Thanks
\$ docker pull sonarqube:7.9.4-community
\$ docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:7.9.4-community
\$ docker pull newtmitch/sonar-scanner:4-alpine
Goto your root directory of the Project
\$ docker run -it -v $(pwd):/usr/src --link sonarqube:7.9.4-community newtmitch/sonar-scanner:4-alpine \
-D sonar.host.url=http://sonarqube:9000 \
-D sonar.scm.provider=git \
-D sonar.projectBaseDir=./src \
-D sonar.sources=. \
-D sonar.projectName='Test-Project'
(NOTE: Above I assume that your source code is inside- src folder, if not please change accordingly)
Go to http://localhost:9000 You will now see a new project - "Test-Project" which has completely analyzed the source code that you ran from your root directory.
Documentation click
\$ npm i -D sonarqube-scanner
In package.json add a new script: "sonar": "node sonar-project.js"
add a file in your root-directory: sonar-project.js
Copy following code in sonar-project.js:
const sonarqubeScanner = require('sonarqube-scanner');
sonarqubeScanner({
serverUrl: 'http://localhost:9000',
options: {
'sonar.sources': 'src',
'sonar.tests': 'src',
'sonar.inclusions': 'src/**/*.ts', // Entry point of your code
'sonar.test.inclusions': 'src/**/*.spec.ts,src/**/*.spec.jsx',
},
}, () => {
console.log('Error Occurred while scanning');
});
\$ npm run sonar
Documentation click