Hello everyone,
I am facing an issue when running SonarScanner in my GitLab CI/CD pipeline. The analysis fails with a connection error to the SonarQube server.
Context
Environment: GitLab CI/CD
Image used: sonarsource/sonar-scanner-cli:11
Java version: 17.0.12 Amazon Inc. (64-bit)
OS: Linux 5.15.0-79-generic amd64
SonarScanner CLI: 6.2.1.4610
SonarQube URL: :9000
Issue encountered
Running the following command fails:
$ sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}"
The error displayed in the logs is:
ERROR Error during SonarScanner CLI executionjava.lang.IllegalStateException: Failed to get server versionCaused by: java.SocketTimeoutException: Connect timed out
Full logs
Resolving secrets
Preparing the "docker" executor
Using Docker executor with image sonarsource/sonar-scanner-cli:11 ...
Pulling docker image sonarsource/sonar-scanner-cli:11 ...
Using docker image sha256:3799521e5ac627eeae7bf83028dbb7a3594bef71c9c7b83ea37de21282d91f2d for sonarsource/sonar-scanner-cli:11 with digest sonarsource/sonar-scanner-cli@sha256:0b90dedf01ef875d69a5a151f73d72b8288a319b39cdfd2ee32a729027a00785 ...
Preparing environment
Running on runner-sj5ce8nr8-project-19878086-concurrent-0 via icrunner...
Getting source from Git repository
Fetching changes...
Initialized empty Git repository in /builds/w-seils/test-ci/.git/
Created fresh repository.
Checking out 00499271 as detached HEAD (ref is master)...
Skipping Git submodules setup
Restoring cache
Checking cache for sonar-cache-master-protected...
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:13
Using docker image sha256:3799521e5ac627eeae7bf83028dbb7a3594bef71c9c7b83ea37de21282d91f2d for sonarsource/sonar-scanner-cli:11 with digest sonarsource/sonar-scanner-cli@sha256:0b90dedf01ef875d69a5a151f73d72b8288a319b39cdfd2ee32a729027a00785 ...
$ sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}"
11:30:57.180 INFO Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
11:30:57.183 INFO Project root configuration file: /builds/w-seils/test-ci/sonar-project.properties
11:30:57.195 INFO SonarScanner CLI 6.2.1.4610
11:30:57.197 INFO Java 17.0.12 Amazon Inc. (64-bit)
11:30:57.198 INFO Linux 5.15.0-79-generic amd64
11:30:57.224 INFO User cache: /builds/w-seils/test-ci/.sonar/cache
11:31:09.432 INFO EXECUTION FAILURE
11:31:09.434 INFO Total time: 12.256s
11:31:09.434 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Failed to get server version
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:194)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:117)
at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:63)
Suppressed: java.lang.IllegalStateException: Call to URL [:9000/api/v2/analysis/version] failed
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callUrl(ScannerHttpClient.java:159)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callApi(ScannerHttpClient.java:126)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callRestApi(ScannerHttpClient.java:104)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:189)
... 3 common frames omitted
Caused by: java.SocketTimeoutException: Connect timed out
at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:551)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602)
at java.base/java.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.Socket.connect(Socket.java:633)
at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:128)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:221)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callUrl(ScannerHttpClient.java:157)
... 6 common frames omitted
Caused by: java.lang.IllegalStateException: Call to URL [:9000/api/server/version] failed
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callUrl(ScannerHttpClient.java:159)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callApi(ScannerHttpClient.java:126)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callWebApi(ScannerHttpClient.java:112)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:192)
... 3 common frames omitted
Caused by: java.SocketTimeoutException: Connect timed out
at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:551)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602)
at java.base/java.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.Socket.connect(Socket.java:633)
at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:128)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:221)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callUrl(ScannerHttpClient.java:157)
... 6 common frames omitted
11:31:09.436 ERROR
11:31:09.436 ERROR Re-run SonarScanner CLI using the -X switch to enable full debug logging.
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1
Actions already taken
Checked the SonarQube URL: curl :9000 → Timeout
Pinged the server: ping sonarqube.wseils-dev → Responds correctly
Verified firewall rules and network restrictions
Added the -X option for debug mode → Same error
Questions
Could this be a network issue on the GitLab Runner side?
Are there any specific parameters needed for connecting to SonarQube?
Has anyone encountered this issue before and found a solution?
Thanks in advance for your help!