Step 1: Install Docker
Step 2: Pull SonarQube by going to your terminal and typing:
`docker pull sonarqube`
Step 3: Then run SonarQube by typing:
`docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest`
# This bypasses bootstrap checks
You can also run this by clicking on the run icon in the docker UI.
Step 4: Navigate to SonarQube by going to http://localhost:9000
* The default login is ‘admin’ and ‘admin’
Step 5: Create a project by clicking on create project and with the following:
- Enter name
- Type of project – local/manual
- Create token
- What option – other
- OS – Choose your OS
You will need the IP address of your docker instance, you can get that by going to the terminal and running
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' sonarqube
Step 6: For the site, you’ll need to create a sonar-project.properties file in the root directory of files you need to analyze.
Step 7: Put this content in the file (replacing the ALL_CAPS words with the correct info):
# must unique in a given SonarQube instance
sonar.projectKey=PROJECT_KEY
# --- optional properties ---
# defaults to project key
sonar.projectName=PROJECT NAME
# defaults to 'not provided'
sonar.projectVersion=1.0
sonar.host.url= http://IP_ADDRESS:9000
# Path is relative to the sonar-project.properties file. Defaults to .
sonar.sources=.
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
Step 8: After saving the file, go back to terminal to run the command to analyze the files.
Step 9: cd to the directory of files. Replace IP_ADDRESS, THE_KEY, and PATH with the correct info and run the following command:
docker run --rm --link sonarqube \
-e SONAR_HOST_URL=" http://IP_ADDRESS:9000" \
-e SONAR_LOGIN="THE_KEY_THAT_WAS_GENERATED" \
-v "/PATH/TO/FILES/TO/ANALYZE:/usr/src" \
sonarsource/sonar-scanner-cli