I am using Sonarqube and CircleCI for code quality scan.However, I don't know how if it is possible to start up a Sonarqube Server on CircleCI and use it to run the scanner.

This is my current config.yaml

version: 2.1executors:scanner:docker:- image: openjdk:11commands:check-code-quality:description: Check Code Qualityparameters:sonar_server_url:type: stringdescription: "URL of your SonarQube server. e.g.: http://my.sonarqube,server:9000"default: "$SONAR_SERVER"sonar_login:description: "Authentication key (sonar.login paramter) to access SonarQube and perform analysis"type: stringdefault: "$SONAR_TOKEN"sonar_sources:description: "Where the files are located?"type: stringdefault: "$SONAR_SOURCES"steps:- run:name: Install Sonarqube scannercommand: |wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.2.0.1873.zipunzip sonar-scanner-cli-4.2.0.1873.zip- run:name: Run Sonarscannercommand: |export SONAR_SCANNER_OPTS="-Xmx2048m"eval ./sonar-scanner-4.2.0.1873/bin/sonar-scanner \-Dsonar.projectKey=projectKey-Dsonar.host.url=<< parameters.sonar_server_url >> \-Dsonar.sources=<< parameters.sonar_sources >> \-Dsonar.login=<< parameters.sonar_login >>jobs:check-code-job:executor: scannersteps:- check-code-qualityworkflows:check-code-quality-flow:jobs:- check-code-job:context: lineclass

There is an error log when the job being executed:

...Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from serverat 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 moreCaused by: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9000at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.R...

This indicates that the Sonarqube Server is missing.

If you have experience running sonar-scanner on CircleCI please help.Thank you.

1

Best Answer


After I change the image to sonarqube:8.9-community and fix the missing \ in the sonar-scanner command (at the end of -Dsonar.projectKey), it works.