I’m running SonarQube v10.6 CE in Docker, and I want to run Scanner, which it provided to me as a download for a local run with the following tutorial:
Running a SonarQube analysis is straightforward. You just need to execute the following commands in your project's folder.
`sonar-scanner.bat
-D"sonar.projectKey=my-project" -D"sonar.sources=."
-D"sonar.host.url=http://localhost:9000"
-D"sonar.token=sqp_149180b8b..."`
However, I want to run Scanner in Docker instead of running random executables on my machine.
I’ve prepared this script, as there is a need for workaround to route to host network’s SonarQube, which wasn’t documented: docker run --rm -e SONAR_HOST_URL="http://host.docker.internal:9000" --add-host=host.docker.internal:host-gateway -v "C:\Projects\hie-engine:/usr/src" sonarsource/sonar-scanner-cli
However, this is not enough, because I also need to provide all the keys like token, -D"sonar.projectKey=my-project".
My question is, how can I write a command that passes these auth parameters to the Scanner Docker image? Please, can you update the documentation to cover this? There are no articles with a working solution.
It also likely may be possible to pass a sonar-project.properties file, but I’d rather use the parameters as part of my Docker script; this file isn’t generated anyway.
Hi @vodoc82730,
Welcome to the community.
I find more information in the V9.9 documentation. Seems that documentation evolved with less detail since 10.3.
You can provide the token like that :
-e SONAR_LOGIN=“myAuthenticationToken” \
You can also put a sonar-project.properties at the root directory of source. It will be easier to use all possible parameters as projectKey, projectName, exclusion, inclusion, coverage path …
Thanks, I tried that but -e SONAR_LOGIN didn’t work. However, in that old documentation I see -e SONAR_SCANNER_OPTS, so I added the CLI parameter there as:
I had to also add “-Dsonar.java.binaries=build,out,logs_*” though, which wasn’t mentioned either (why doesn’t this use .gitignore by default?), because I was getting:
ERROR: Error during SonarScanner execution
org.sonar.java.AnalysisException: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.
By the way, I originally wanted to use SonarLint (10.8.1.79205) plugin of IntelliJ IDEA, but after configuring both the connection and binding project, it doesn’t do anything at all. In logs I saw one authentication error, and then it only says “Analysis skipped as the engine is not ready yet” after every action, without showing any progress. I give up on this for now, I won’t spend time troubleshooting it anymore, it’s just that I’d be glad if this onboarding process got fixed.