How to run Scanner in Docker, passing parameters like token

Execute the Scanner

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:

-e SONAR_SCANNER_OPTS=“-Dsonar.projectKey=my-project -Dsonar.token=sqp_6462”

and now it works, great!

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 any chance, are you able to request from developers to add this to the documentation, preferably even to the http://localhost:9000/tutorials?id=my-project&selectedTutorial=local page? It’s really difficult to contact them if you aren’t on a paid plan.

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.

1 Like

Hi @vodoc82730,

I opened a new topic for improving the documentation.
You can completed it if needed.

I suggest you open another topic for your sonarlint problem.

1 Like