Running SonarScanner from the Docker image Help!

Must-share information (formatted with Markdown):

  • “SONARQUBE_HOME=/opt/sonarqube”,
    “SONAR_VERSION=8.8.0.42792”
  • attempting to scan locally a folder by Running SonarScanner from the Docker image

the folder that I am trying to scan is on home/$USER/$foldername

my property file looks like this that is inside the root of $foldername

sonar.projectKey=projectkey
sonar.projectName=projectname
sonar.projectVersion=1.0 
sonar.language=py
sonar.sourceEncoding=UTF-8
sonar.host.url=http://172.17.0.2:9000/
sonar.login=admin 
sonar.password=admin
sonar.projectBaseDir=/home/$USER/$foldername

I attempted to use

docker run     
--rm \
--network=host \
-e SONAR_HOST_URL="http://127.0.0.1:9000/"  \
-e SONAR_LOGIN="c70a28c91663d7c91a863e61586831f5ed08e620" \
-v $(pwd)/$foldername:/usr/src/ \
sonarsource/sonar-scanner-cli

and the error I get is

sr/src/.scannerwork     sonarsource/sonar-scanner-cli
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.1.2450
INFO: Java 11.0.11 AdoptOpenJDK (64-bit)
INFO: Linux 5.10.25-linuxkit amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 8.8.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=59ms
INFO: Server id: BF41A1F2-AXkez8-621_-p5FTDWy4
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=33ms
INFO: Load/download plugins (done) | time=1098ms
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 2.390s
INFO: Final Memory: 5M/24M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

I asked someone who attempt this before and they told me to use zaquestion/sonarqube-scanner instead of sonarsource/sonar-scanner-cli

by using

docker run -t -v $(pwd)/idevops-crmservice:/usr/src/ zaquestion/sonarqube-scanner

but the error says ERROR: SonarQube server [http://localhost:9000] can not be reached but on my properties file it has sonar.host.url=http://172.17.0.2:9000/ so its not reading the sonar-project.properties

INFO: Scanner configuration file: /root/sonar_home/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.4.0.2170
INFO: Java 15 Oracle Corporation (64-bit)
INFO: Linux 5.10.25-linuxkit amd64
INFO: User cache: /root/.sonar/cache
ERROR: SonarQube server [http://localhost:9000] can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.252s
INFO: Final Memory: 3M/20M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
        at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
        at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
        at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
        at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
        at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
        at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
        ... 7 more
Caused by: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9000
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:265)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connect(RealConnection.java:183)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.Transmitter.newExchange(Transmitter.java:169)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)
        at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:114)
        at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)
        at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
        ... 10 more
Caused by: java.net.ConnectException: Connection refused
        at java.base/sun.nio.ch.Net.pollConnect(Native Method)
        at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:660)
        at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542)
        at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597)
        at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333)
        at java.base/java.net.Socket.connect(Socket.java:648)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.platform.Platform.connectSocket(Platform.java:130)
        at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:263)
        ... 31 more
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

I’m not sure what to do

Hi,

Welcome to the community!

Can you start with the vanilla scanner as a local binary in your $PATH? That will eliminate Docker questions while you get the basic mechanics of analysis down.

Along those lines, I would made some adjustments to your analysis properties:

This parameter is long-since dropped. You can remove it

Two things here. First these are the default admin credentials. You would have been forced to change the password on first login, so I’m 95% sure admin/admin is no longer valid in your instance. Second, an analysis/authentication token is preferred to using login/password like this.

Bonus thing: you’re passing an analysis token in your Docker command so there’s no need for these credentials at all. And if you switch to the vanilla scanner as I suggested above, you can pass the same token on that command line too.

Ideally, you should be executing analysis from the project root directory, which means you don’t need this parameter. This param is necessary only when you have to file analysis from some other directory.

In fact, the error from your first try is probably related to your execution directory since the scanner apparently isn’t finding your sonar-project.properties file.

The docs may help

 
Ann

Hey thank you for responding!! I am very new to all of this and with linux. I have heard about setting path but I’m not sure really on how to “vanilla scanner as a local binary in your $PATH ?”

I do want to mention that I was able to run a scan using the .zip from a guide Tutorial - Sonarqube Scanner Installation on Ubuntu Linux [ Step by Step ]

but I don’t want to run it from a .zip I want to run it from a Docker image

Hi,

I have no expertise in Docker. I’ve added that tag to this thread in an attempt to gain the attention of someone who does. In the meantime, did you check out our docs on the topic (linked above)?

 
Ann

ye that’s the one I have been using

I attempted to also use

-Dproject.settings

to tell it where the properties are located at buts it still doesn’t apply it

I also tried setting the values when calling the sonar scan like this

docker run \
	--rm \
	--net host \
	-e SONAR_HOST_URL="http://192.168.1.108:9000" \
	-v ${PWD}:/root/src  \
	sonarsource/sonar-scanner-cli \
	-Dsonar.projectKey=crmservice \
    -Dsonar.sonar.projectName=crmservice \
    -Dsonar.sonar.projectVersion=1.0 \
    -Dsonar.sonar.sourceEncoding=UTF-8 \
    -Dsonar.sonar.host.url=http://192.168.1.108:9000 \
    -Dsonar.login=c70a28c91663d7c91a863e61586831f5ed08e620 

which

doesn’t end up scanning nothing even tho the Execution was success I’m just confused

-crmservice$ docker run \
> --rm \
> --net host \
> -e SONAR_HOST_URL="http://192.168.1.108:9000" \
> -v ${PWD}:/root/src  \
> sonarsource/sonar-scanner-cli \
> -Dsonar.projectKey=idevops-crmservice \
>     -Dsonar.sonar.projectName=idevops-crmservice \
>     -Dsonar.sonar.projectVersion=1.0 \
>     -Dsonar.sonar.language=py \
>     -Dsonar.sonar.sourceEncoding=UTF-8 \
>     -Dsonar.sonar.host.url=http://192.168.1.108:9000 \
>     -Dsonar.login=c70a28c91663d7c91a863e61586831f5ed08e620 \
>     -Dsonar.sonar.projectBaseDir=/root/src/
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.1.2450
INFO: Java 11.0.11 AdoptOpenJDK (64-bit)
INFO: Linux 5.10.25-linuxkit amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 8.8.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=71ms
INFO: Server id: BF41A1F2-AXkez8-621_-p5FTDWy4
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=37ms
INFO: Load/download plugins (done) | time=3751ms
INFO: Process project properties
INFO: Process project properties (done) | time=1ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=3ms
INFO: Project key: idevops-crmservice
INFO: Base dir: /usr/src
INFO: Working dir: /usr/src/.scannerwork
INFO: Load project settings for component key: 'idevops-crmservice'
INFO: Load project settings for component key: 'idevops-crmservice' (done) | time=26ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=85ms
INFO: Load active rules
INFO: Load active rules (done) | time=1614ms
WARN: SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
INFO: Indexing files...
INFO: Project configuration:
INFO: 0 files indexed
INFO: ------------- Run sensors on module idevops-crmservice
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=38ms
INFO: Sensor CSS Rules [cssfamily]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor CSS Rules [cssfamily] (done) | time=1ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=1ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=1ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=1ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=2ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=0ms
INFO: SCM Publisher No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
INFO: CPD Executor Calculating CPD for 0 files
INFO: CPD Executor CPD calculation finished (done) | time=0ms
INFO: Analysis report generated in 94ms, dir size=92 KB
INFO: Analysis report compressed in 10ms, zip size=11 KB
INFO: Analysis report uploaded in 32ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://192.168.1.108:9000/dashboard?id=idevops-crmservice
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://192.168.1.108:9000/api/ce/task?id=AXk4snc-CQ0RNJmIhvZa
INFO: Analysis total time: 3.120 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 8.660s
INFO: Final Memory: 6M/24M
INFO: ------------------------------------------------------------------------