ERROR: SonarQube server [] can not be reached

Getting “ERROR: SonarQube server can not be reached” While Triggering Pipeline .
But I can access “[http://PrivateIp:9000]” From my browser .

Both the gitlab runner & sonarqube hosted on same machine .

Configured all the steps accordingly .

Gitlab.yaml

sonarqube-check:
stage: scan
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [“”]
variables:
SONAR_USER_HOME: “${CI_PROJECT_DIR}/.sonar” # Defines the location of the analysis task cache
#GIT_DEPTH: “0” # Tells git to fetch all the branches of the project, required by the analysis task
SONAR_PROJECT_KEY: “”
SONAR_PROJECT_NAME: “$CI_PROJECT_NAME”
SONAR_PROJECT_VERSION: “$CI_BUILD_ID”
cache:
key: “${CI_JOB_NAME}”
paths:
- .sonar/cache
script:
- pwd
- docker run --rm -e SONAR_HOST_URL=“” -e SONAR_LOGIN=“” -v “/home/projects/project1:/usr/src”
sonarsource/sonar-scanner-cli:latest
sonar.projectKey=“”

sonar-scanner.properties
SONAR_HOST_URL=“”
SONAR_LOGIN=“”
sonar.project.settings=sonar-project.properties

sonar-project.properties
SONAR_PROJECT_KEY=e2co
SONAR_PROJECT_NAME=e2co
SONAR_PROJECT_VERSION=1.0
sonar.qualitygate.wait=true
#sonar.sources=.
sonar.sourceEncoding=UTF-8

Error
Running with gitlab-runner 14.6.0 (5316d4ac)
on e2co recordkeeper 7T7xE1dN
Preparing the “shell” executor
00:00
Using Shell executor…
Preparing environment
00:00
Running on cicdserver-ThinkCentre-M72e…
Getting source from Git repository
00:00
Fetching changes with git depth set to 50…
Reinitialized existing Git repository in /home/gitlab-runner/builds/7T7xE1dN/0/e2co/recordkeeper/.git/
Checking out 9d938fc2 as sonarqubetest…
Removing build/test
Skipping Git submodules setup
Restoring cache
00:00
Checking cache for sonarqube-check…
Runtime platform arch=amd64 os=linux pid=9138 revision=5316d4ac version=14.6.0
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
Executing “step_script” stage of the job script
00:04
$ dos2unix version.sh
dos2unix: converting file version.sh to Unix format…
$ chmod +x version.sh
$ export VERSION=$(./version.sh “$CI_COMMIT_TAG” “$CI_COMMIT_REF_NAME”)
$ echo “Build version is $VERSION”
Build version is sonarqubetest
$ pwd
/home/gitlab-runner/builds/7T7xE1dN/0/e2co/recordkeeper
$ docker run --rm -e SONAR_HOST_URL=“” -e SONAR_LOGIN=“” -v “/home/projects/project1:/usr/src” sonarsource/sonar-scanner-cli:latest sonar.projectKey=“”
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14 Alpine (64-bit)
INFO: Linux 5.4.0-109-generic amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
ERROR: SonarQube server can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.299s
INFO: Final Memory: 3M/14M
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(Native Method)
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.lang.IllegalArgumentException: Expected URL scheme ‘http’ or ‘https’ but no colon was found
at org.sonarsource.scanner.api.internal.shaded.okhttp.HttpUrl$Builder.parse(HttpUrl.java:1332)
at org.sonarsource.scanner.api.internal.shaded.okhttp.HttpUrl.get(HttpUrl.java:917)
at org.sonarsource.scanner.api.internal.shaded.okhttp.Request$Builder.url(Request.java:165)
at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:111)
at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
… 10 more
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
ERROR: Job failed: exit status 1

Can any one suggest what is problem & how it could be resolved

Hey there.

It appears the value being to the scanner isn’t valid.

Moreover, it appears you’ve really overcomplicated your .gitlab-ci.yml file.

After defining the SONAR_TOKEN and SONAR_HOST_URL environment variables (configured under Settings > CI/CD > Variables in GitLab), and creating a sonar-project.properties file with sonar.projectKey and sonar.qualitygate.wait` defined), all you need is this:

sonarqube-check:
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner
  allow_failure: true
  only:
    - merge_requests
    - master # or the name of your main branch
    - develop

@Colin Thank you for your prompt response.

Yes i did the changes you have mentioned above .

But its the same .
Running with gitlab-runner 14.6.0 (5316d4ac)
on e2co recordkeeper 7T7xE1dN
Preparing the “shell” executor
00:00
Using Shell executor…
Preparing environment
00:00
Running on cicdserver-ThinkCentre-M72e…
Getting source from Git repository
00:01
Fetching changes…
Reinitialized existing Git repository in /home/gitlab-runner/builds/7T7xE1dN/0/e2co/recordkeeper/.git/
Checking out 0d8826d5 as sonarqubetest…
Removing build/test
Skipping Git submodules setup
Restoring cache
00:00
Checking cache for sonarqube-check…
Runtime platform arch=amd64 os=linux pid=23916 revision=5316d4ac version=14.6.0
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
Executing “step_script” stage of the job script
00:00
$ dos2unix version.sh
dos2unix: converting file version.sh to Unix format…
$ chmod +x version.sh
$ export VERSION=$(./version.sh “$CI_COMMIT_TAG” “$CI_COMMIT_REF_NAME”)
$ echo “Build version is $VERSION”
Build version is sonarqubetest
$ sonar-scanner
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/gitlab-runner/builds/7T7xE1dN/0/e2co/recordkeeper/sonar-project.properties
INFO: SonarQube Scanner 4.2.0.1873
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 5.4.0-109-generic amd64
INFO: User cache: /home/gitlab-runner/builds/7T7xE1dN/0/e2co/recordkeeper/.sonar/cache
ERROR: SonarQube server [http://localhost:9000] can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.273s
INFO: Final Memory: 2M/14M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
at java.base/java.security.AccessController.doPrivileged(Native Method)
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:113)
at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:98)
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
… 10 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
at java.base/java.net.Socket.connect(Unknown Source)
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 SonarQube Scanner using the -X switch to enable full debug logging.
ERROR: Job failed: exit status 1

Not sure what went wrong. Same IP I can access from my browser .

sonar-project.properties file :
sonar.projectKey=<Token created in sonarqube & decalred in Gitlab variable>
sonar.projectName=e2co
sonar.projectVersion=1.0
sonar.qualitygate.wait=true
sonar.sources=.
sonar.sourceEncoding=UTF-8

Its working fine now
Thank you @Colin

Thanks for the follow-up! What did you have to change?

I tried running sonarqube as a container in ubuntu machine & followed the above steps mentioned .

docker run -d --name sonarqube -p 9000:9000 sonarqube

Where previously sonarqube was running as a service that made some configuration issue with gitlab pipeline