Failed to request and parse 'https://sonarqube-dev.*******.com/api/server/version': Name or service

I’m trying to run SonarQube analytics against a docker container for a .net Core application. We already have the sonarqube server : https://sonarqube-dev.domain.com/

I’ve created the dockerfile as follows:

##############
## Stage 1 ##
#############
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build-env
WORKDIR /app

## Arguments for setting the Sonarqube Token and the Project Key
ARG SONAR_TOKEN
ARG SONAR_PRJ_KEY

## Setting the Sonarqube Organization and Uri
##ENV SONAR_ORG "admin"
##ENV SONAR_HOST "https://sonarcloud.io"
ENV SONAR_HOST "https://sonarqube-dev.domain.com/"

## Install Java, because the sonarscanner needs it.
RUN mkdir /usr/share/man/man1/
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y openjdk-11-jre


## Install sonarscanner
RUN dotnet tool install --global dotnet-sonarscanner --version 5.3.1

## Install report generator
RUN dotnet tool install --global dotnet-reportgenerator-globaltool --version 4.8.12

## Set the dotnet tools folder in the PATH env variable
ENV PATH="${PATH}:/root/.dotnet/tools"

## Start scanner
RUN dotnet sonarscanner begin \
	/k:"$SONAR_PRJ_KEY" \
	/d:sonar.host.url="$SONAR_HOST" \
	/d:sonar.login="$SONAR_TOKEN" \ 
	/d:sonar.coverageReportPaths="coverage/SonarQube.xml"

## Copy the applications .csproj
COPY /src/WebApp/*.csproj ./src/WebApp/

## Restore packages
RUN dotnet restore "./src/WebApp/WebApp.csproj" -s "https://api.nuget.org/v3/index.json"

## Copy everything else
COPY . ./

## Build the app
RUN dotnet build "./src/WebApp/WebApp.csproj" -c Release --no-restore

## Run dotnet test setting the output on the /coverage folder
RUN dotnet test test/WebApp.Tests/*.csproj --collect:"XPlat Code Coverage" --results-directory ./coverage

## Create the code coverage file in sonarqube format using the cobertura file generated from the dotnet test command
RUN reportgenerator "-reports:./coverage/*/coverage.cobertura.xml" "-targetdir:coverage" "-reporttypes:SonarQube"

## Publish the app
RUN dotnet publish src/WebApp/*.csproj -c Release -o /app/publish --no-build --no-restore

## Stop scanner
RUN dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"

#############
## Stage 2 ##
#############
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim
WORKDIR /app
COPY --from=build-env /app/publish .
ENTRYPOINT ["dotnet", "WebApp.dll"]

Whenever I run the build command, docker build -t containername .
I get this error:

[build-env 6/14] RUN dotnet sonarscanner begin /k:“ProjTest” /d:sonar.host.url=“https://sonarqube-dev.domain.com” /d:sonar-login=“admin” /d:sonar-password=“Tme^5c5LJowc5XxBHJTXqHDx8q”:
#12 0.667 SonarScanner for MSBuild 5.3.1
#12 0.667 Using the .NET Core version of the Scanner for MSBuild
#12 0.776 Pre-processing started.
#12 0.778 Preparing working directories…
#12 0.803 16:12:29.035 Updating build integration targets…
#12 0.967 16:12:29.199 Failed to request and parse ‘https://sonarqube-dev.domain.com/api/server/version’: Name or service not known (sonarqube-dev.domain.com:443)
#12 0.974 Unhandled exception. System.Net.Http.HttpRequestException: Name or service not known (sonarqube-dev.domain.com:443)
#12 0.990 —> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known
#12 0.990 at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
#12 0.990 at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
#12 0.990 at System.Net.Sockets.Socket.g__WaitForConnectWithCancellation|283_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
#12 0.990 at System.Net.Http.HttpConnectionPool.DefaultConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
#12 0.990 at System.Net.Http.ConnectHelper.ConnectAsync(Func3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken) #12 0.990 --- End of inner exception stack trace --- #12 0.990 at System.Net.Http.ConnectHelper.ConnectAsync(Func3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
#12 0.990 at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
#12 0.990 at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
#12 0.990 at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
#12 0.990 at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
#12 0.990 at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
#12 0.990 at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
#12 0.990 at SonarScanner.MSBuild.PreProcessor.WebClientDownloader.Download(String url, Boolean logPermissionDenied)
#12 0.990 at SonarScanner.MSBuild.PreProcessor.SonarWebService.<>c__DisplayClass18_0.<b__0>d.MoveNext()
#12 0.990 — End of stack trace from previous location —
#12 0.990 at SonarScanner.MSBuild.PreProcessor.SonarWebService.DoLogExceptions[T](Func`1 op, String url)
#12 0.990 at SonarScanner.MSBuild.PreProcessor.SonarWebService.DownloadServerVersion()
#12 0.990 at SonarScanner.MSBuild.PreProcessor.SonarWebService.GetServerVersion()
#12 0.990 at SonarScanner.MSBuild.PreProcessor.SonarWebService.WarnIfSonarQubeVersionIsDeprecated()
#12 0.990 at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs localSettings)
#12 0.990 at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.Execute(String args)
#12 0.990 at SonarScanner.MSBuild.BootstrapperClass.PreProcess()
#12 0.990 at SonarScanner.MSBuild.BootstrapperClass.Execute()
#12 0.990 at SonarScanner.MSBuild.Program.Execute(String args, ILogger logger)
#12 0.990 at SonarScanner.MSBuild.Program.Execute(String args)
#12 0.990 at SonarScanner.MSBuild.Program.Main(String args)
#12 0.990 at SonarScanner.MSBuild.Program.(String args)
executor failed running [/bin/sh -c dotnet sonarscanner begin /k:“ProjTest” /d:sonar.host.url=“https://sonarqube-dev.domain.com” /d:sonar-login=“admin” /d:sonar-password=“Tme^5c5LJowc5XxBHJTXqHDx8q”]: exit code: 134

Also using Sonarqube 9.3.0.51899

Any help will be appreciated

Hi,

Are you able to access that URL in a browser? Are you able to curl it from the build agent? This is not an analysis question, but a question of the availability / reachability of your SonarQube server. And/or, this is a question of your proxy setup.

 
HTH,
Ann