Sonar Scanner MSBuild for C# Project inside Docker build

Trying to run sonar scan using sonar scanner msbuild part of the docker build alongside Application build using sonarscanner begin and end commands. The Sonarscanner end is failing with unable to connect(connect timeout) when configured to connect via corporate proxy.

I’ve added Proxy env variables that are required for dotnet scanner and also added SONAR_SCANNER_OPTS = “-Dhttp.proxyHost=yourProxyHost -Dhttp.proxyPort=yourProxyPort” as environment variables(this is just an example but I’ve replaced with actual values).

Still no luck and seeing the can’t connect and connection timed out error

here are the logs from our CI/CD pipeline:

#35 31.59 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
#35 31.59 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
#35 31.59 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
#35 31.59 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
#35 31.59 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
#35 31.59 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)
#35 31.59 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)
#35 31.59 at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:115)
#35 31.59 at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)
#35 31.59 at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
#35 31.59 … 10 more
#35 31.59 ERROR:
#35 31.60 The SonarScanner did not complete successfully
#35 31.60 03:00:54.148 Post-processing failed. Exit code: 1
#35 ERROR: process “/bin/sh -c dotnet sonarscanner end /d:sonar.token="${SONAR_TOKEN}"” did not complete successfully: exit code: 1

Hey there.

Have you read these docs, which mention also setting environment variables other than SONAR_SCANNER_OPTS?

You also need to set the appropriate proxy environment variables used by .NET. HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, and NO_PROXY are all supported. You can find more details here.

Please also make sure you include full logs from the scanner, not just the last few lines of the logs. :slight_smile: It’s impossible to know what was going on before!

Colin - I’ve also added the required environment variables for .NET in the Dockerfile but of no avail.

ENV HTTP_PROXY=http://sample-proxy:80

ENV http_proxy=http://sample-proxy:80

ENV HTTPS_PROXY=http://sample-proxy:80

ENV https_proxy=http://sample-proxy:80

ENV ALL_PROXY=http://sample-proxy:80

RUN echo "http_proxy=\"${HTTP_PROXY}\"" >> /etc/environment

RUN echo "https_proxy=\"${HTTP_PROXY}\"" >> /etc/environment

RUN echo "HTTP_PROXY=\"${HTTP_PROXY}\"" >> /etc/environment

RUN echo "HTTPS_PROXY=\"${HTTP_PROXY}\"" >> /etc/environment

RUN echo "ALL_PROXY=\"${HTTP_PROXY}\"" >> /etc/environment

ENV SONAR_SCANNER_OPTS=-Dhttp.proxyHost=sample-proxy -Dhttp.proxyPort=80


#35 31.57 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)

#35 31.57 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)

#35 31.57 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)

#35 31.57 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)

#35 31.57 at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:115)

#35 31.57 at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)

#35 31.57 at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)

#35 31.57 ... 10 more

#35 31.57 ERROR:

#35 31.59 The SonarScanner did not complete successfully

#35 31.59 12:38:07.034 Post-processing failed. Exit code: 1

#35 ERROR: process "/bin/sh -c dotnet sonarscanner end /d:sonar.token=\"${SONAR_TOKEN}\"" did not complete successfully: exit code: 1

------

> [publish 17/17] RUN dotnet sonarscanner end /d:sonar.token="***":

31.57 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)

31.57 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)

31.57 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)

31.57 at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:115)

31.57 at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)

31.57 at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)

31.57 ... 10 more

31.57 ERROR:

31.59 The SonarScanner did not complete successfully

31.59 12:38:07.034 Post-processing failed. Exit code: 1

Please attach the complete logs from dotnet sonarscanner end!

#35 [publish 17/17] RUN dotnet sonarscanner end /d:sonar.token="squ_c5d1a3307762a68f888727c727e9262169e371d8"

#35 0.848 SonarScanner for MSBuild 10.1.2


this is the complete log

#35 0.848 Using the .NET Core version of the Scanner for MSBuild

#35 0.911 Post-processing started.

#35 1.034 12:33:37.754 Starting with Scanner for .NET v8 the way the `sonar.projectBaseDir` property is automatically detected has changed and this has an impact on the files that are analyzed and other properties that are resolved relative to it like `sonar.exclusions` and `sonar.test.exclusions`. If you would like to customize the behavior, please set the `sonar.projectBaseDir` property to point to a directory that contains all the source code you want to analyze. The path may be relative (to the directory from which the analysis was started) or absolute.

#35 1.222 Using the supplied value for SONAR_SCANNER_OPTS. Value: -Dhttp.proxyHost=cat-proxy.private

#35 1.229 Calling the SonarScanner CLI...

#35 1.313 INFO: Scanner configuration file: /root/.dotnet/tools/.store/dotnet-sonarscanner/10.1.2/dotnet-sonarscanner/10.1.2/tools/netcoreapp3.1/any/sonar-scanner-5.0.1.3006/conf/sonar-scanner.properties

#35 1.313 INFO: Project root configuration file: /build/nMessaging/Impl/UtilizationLambda/TimestampedEvents.Function/.sonarqube/out/sonar-project.properties

#35 1.373 INFO: SonarScanner 5.0.1.3006

#35 1.373 INFO: Java 17.0.15 Debian (64-bit)

#35 1.373 INFO: Linux 5.10.236-228.935.amzn2.x86_64 amd64

#35 1.375 INFO: SONAR_SCANNER_OPTS=-Dhttp.proxyHost=cat-proxy.private -Djavax.net.ssl.trustStore=/usr/lib/jvm/java-17-openjdk-amd64/lib/security/cacerts -D<sensitive data removed>

#35 1.630 INFO: User cache: /root/.sonar/cache

#35 31.70 INFO: ------------------------------------------------------------------------

#35 31.70 INFO: EXECUTION FAILURE

#35 31.70 INFO: ------------------------------------------------------------------------

#35 31.70 INFO: Total time: 30.395s

#35 31.70 ERROR: SonarQube server [https://sonarqube.cat.com] can not be reached

#35 31.71 INFO: Final Memory: 4M/20M

#35 31.71 INFO: ------------------------------------------------------------------------

#35 31.71 ERROR: Error during SonarScanner execution

#35 31.71 org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis

#35 31.71 at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)

#35 31.71 at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)

#35 31.71 at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)

#35 31.71 at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)

#35 31.71 at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)

#35 31.71 at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)

#35 31.71 at org.sonarsource.scanner.cli.Main.execute(Main.java:74)

#35 31.71 at org.sonarsource.scanner.cli.Main.main(Main.java:62)

#35 31.71 Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server

#35 31.71 at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)

#35 31.71 at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)

#35 31.71 at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)

#35 31.72 at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)

#35 31.72 ... 7 more

#35 31.72 Caused by: java.net.SocketTimeoutException: Connect timed out

#35 31.72 at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:551)

#35 31.72 at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602)

#35 31.72 at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)

#35 31.72 at java.base/java.net.Socket.connect(Socket.java:633)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.platform.Platform.connectSocket(Platform.java:130)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connectSocket(RealConnection.java:263)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.RealConnection.connect(RealConnection.java:183)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.Transmitter.newExchange(Transmitter.java:169)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)

#35 31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)

#35 31.72 at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:115)

#35 31.72 at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)

#35 31.72 at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)

#35 31.72 ... 10 more

#35 31.72 ERROR:

#35 31.73 The SonarScanner did not complete successfully

#35 31.73 12:34:08.45 Post-processing failed. Exit code: 1

#35 ERROR: process "/bin/sh -c dotnet sonarscanner end /d:sonar.token=\"${SONAR_TOKEN}\"" did not complete successfully: exit code: 1

------

> [publish 17/17] RUN dotnet sonarscanner end /d:sonar.token="squ_c5d1a3307762a68f888727c727e9262169e371d8":

31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)

31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.getResponseWithInterceptorChain(RealCall.java:221)

31.72 at org.sonarsource.scanner.api.internal.shaded.okhttp.RealCall.execute(RealCall.java:81)

31.72 at org.sonarsource.scanner.api.internal.ServerConnection.callUrl(ServerConnection.java:115)

31.72 at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:99)

31.72 at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)

31.72 ... 10 more

31.72 ERROR:

31.73 The SonarScanner did not complete successfully

31.73 12:34:08.45 Post-processing failed. Exit code: 1

It definitely failed because of connection error but I tried everything possible but still of no avail

Have you tried using https.proxyHost rather than http.proxyHost?