GitLab CI/CD中SonarScanner连接SonarQube超时问题求助
GitLab CI/CD中SonarScanner连接SonarQube超时问题
在GitLab CI/CD流水线中运行SonarScanner时,代码分析因SonarQube服务器连接超时失败。
环境信息
- 环境:GitLab CI/CD
- 使用镜像:sonarsource/sonar-scanner-cli:11
- Java版本:17.0.12 Amazon.com Inc. (64位)
- 操作系统:Linux 5.15.0-79-generic amd64
- SonarScanner CLI版本:6.2.1.4610
- SonarQube地址:http://sonarqube.wseils-dev.com:9000
遇到的问题
执行以下命令时失败:
$ sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}"
日志核心错误:
ERROR Error during SonarScanner CLI executionjava.lang.IllegalStateException: Failed to get server versionCaused by: java.net.SocketTimeoutException: Connect timed out
完整执行日志:
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.com 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 [http://sonarqube.wseils-dev.com: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.net.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.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) at java.base/java.net.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 [http://sonarqube.wseils-dev.com: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.net.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.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) at java.base/java.net.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
已执行操作
- 测试SonarQube地址:
curl http://sonarqube.wseils-dev.com:9000→ 超时 - 服务器连通性测试:
ping sonarqube.wseils-dev.com→ 响应正常 - 检查防火墙规则及网络限制
- 添加
-X参数启用调试模式 → 错误依旧
疑问
- 是否为GitLab Runner侧的网络问题?
- 连接SonarQube是否需要特定参数?
- 有无用户遇到过此问题并找到解决方案?
感谢各位的帮助!😊
内容的提问来源于stack exchange,提问作者Lenny G.
相关产品推荐
相关产品推荐

