0

I run a Sonar analysis, using sonar-scanner installed on my workstation:

sonar-scanner -Dsonar.host.url=<SONARQUBE_URL> -Dsonar.login=<TOKEN> -Dsonar.projectKey=<SOME_KEY> -Dsonar.java.binaries=target/classes

Everything runs fine. In particuler, the scanner finds 30 source files to analyse.

I run the same Sonar analysis, using the Docker sonar-scanner-cli image:

(winpty) docker run --rm -e SONAR_HOST_URL=<SONARQUBE_URL> -e SONAR_TOKEN=<TOKEN> -e SONAR_SCANNER_OPTS="-Dsonar.projectKey=<SOME_KEY>  -Dsonar.java.binaries=target/classes" -v `pwd`:/usr/src sonarsource/sonar-scanner-cli:4.8.0

It runs smoothly, but it does not detect any source file. Does anybody have a clue?

I added -Dsonar.sources=. to SONAR_SCANNER_OPTS, to no avail.

I replaced `pwd` with /c/Projects/my_project, to no avail.

Thanks in advance.

Ivan dal Bosco
  • 3,233
  • 4
  • 19
  • 24
  • 1
    Are the file correctly mounted in the container? You can check this by running `docker run --rm -e SONAR_HOST_URL= -e SONAR_TOKEN= -e SONAR_SCANNER_OPTS="-Dsonar.projectKey= -Dsonar.java.binaries=target/classes" -v \`pwd\`:/usr/src sonarsource/sonar-scanner-cli:4.8.0 ls -lisa`, this should list the content of `/usr/src`. – Turing85 Jun 09 '23 at 14:29
  • Thanks a lot @Turing85. Your response and https://stackoverflow.com/questions/33566397/docker-run-v-does-not-work-on-windows-using-docker-toolbox put me on the right way. – Ivan dal Bosco Jun 14 '23 at 08:43

1 Answers1

0

The solution was to add a slash in front of `pwd`, that is, -v /`pwd`:/usr/src instead of -v `pwd`:/usr/src. Therefore the correct command is

(winpty) docker run --rm -e SONAR_HOST_URL=<SONARQUBE_URL> -e SONAR_TOKEN=<TOKEN> -e SONAR_SCANNER_OPTS="-Dsonar.projectKey=<SOME_KEY>  -Dsonar.java.binaries=target/classes" -v /`pwd`:/usr/src sonarsource/sonar-scanner-cli:4.8.0
Ivan dal Bosco
  • 3,233
  • 4
  • 19
  • 24