SonarScanner with docker not work

Hi,
I’m using Sonarqube Developer Edition Version 10.0 (build 68432)
I try to run the sonarscanner:
environment Net6, docker

these are the commands:

RUN dotnet sonarscanner begin /k:"$SONAR_PRJ_KEY" /d:sonar.host.url="$SONAR_HOST" /d:sonar.login="$SONARQUBE_ACCESS_TOKEN" /d:sonar.verbose=true /d:sonar.scm.provider=git

RUN dotnet build "Infrastructure.ScoreCard.WebApi.csproj" -c Release
RUN dotnet publish "Infrastructure.ScoreCard.WebApi.csproj" -c Release -o /app/publish


I get this error:

build 19/19] RUN dotnet sonarscanner end /d:sonar.token=“***”:

#25 10.86 06:52:56.349 INFO: EXECUTION FAILURE

#25 10.86 06:52:56.350 INFO: ------------------------------------------------------------------------

#25 10.86 06:52:56.350 INFO: Total time: 9.475s

#25 10.89 06:52:56.381 INFO: Final Memory: 16M/67M

#25 10.89 06:52:56.381 INFO: ------------------------------------------------------------------------

#25 10.89 06:52:56.381 ERROR: Error during SonarScanner execution

#25 10.89 Not inside a Git work tree: /src

#25 11.22 Process returned exit code 2

#25 11.23 The SonarScanner did not complete successfully

#25 11.23 06:52:56.721 Post-processing failed. Exit code: 1


RUN dotnet sonarscanner end /d:sonar.login="$SONARQUBE_ACCESS_TOKEN"```

tried to replace login with token but it didnt help.
java and node are installed

Does someone have any idea what could be the issue ? the logs are not descriptive :(

Hey there.

This is what’s causing the failure.

It looks like you might not be executing analysis from the root of your repository (which would normally contain a .git folder) but from a sub-directory. Is that the case? I can’t tell from the snippet of the Dockerfile shared.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 443


# Use .NET 6 SDK image to build our code
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

# sonar 1 - start
ARG SONARQUBE_ACCESS_TOKEN

## Setting the Sonarqube Organization and Uri
ENV SONAR_HOST "https://sonarqube-infra.internal.tenbis.cloud"
# sonar 1 -end

RUN dotnet tool install --global dotnet-sonarscanner
RUN dotnet tool install --global dotnet-reportgenerator-globaltool
ENV PATH="${PATH}:/root/.dotnet/tools"


# Install prerequisites - curl, jq
RUN apt-get update && apt-get install -y curl jq \
&& apt-get update \
&& rm -rf /var/lib/apt/lists/*


# Copy sources
# First we copy the csproj for donet restore Nuget and then
# The rest of the files (.cs files, settings, etc.)
WORKDIR /src
COPY ["Infrastructure.ScoreCard.WebApi/Infrastructure.ScoreCard.WebApi.csproj", "Infrastructure.ScoreCard.WebApi/"]
COPY ["Infrastructure.ScoreCard.Infrastructure/Infrastructure.ScoreCard.Infrastructure.csproj", "Infrastructure.ScoreCard.Infrastructure/"]
COPY ["Infrastructure.ScoreCard.Core/Infrastructure.ScoreCard.Core.csproj", "Infrastructure.ScoreCard.Core/"]
RUN dotnet restore "Infrastructure.ScoreCard.WebApi/Infrastructure.ScoreCard.WebApi.csproj"
COPY . .

# Dotnet build
# sonar 1 - start
ARG SONARQUBE_ACCESS_TOKEN

## Arguments for setting the Sonarqube Token and the Project Key
ENV SONAR_PRJ_KEY "Infrastructure_ScoreCard_AYGQmmh3-nvuj3vuegXP"

WORKDIR "/src/Infrastructure.ScoreCard.WebApi"

## 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

RUN apt-get update \
    && apt-get install -y curl \
    && curl -sL https://deb.nodesource.com/setup_14.x | bash - \
    && apt-get install -y nodejs

## Setting the Sonarqube Organization and Uri
ENV SONAR_HOST "https://sonarqube-infra.internal.tenbis.cloud"
## Start scanner


RUN dotnet sonarscanner begin /k:"$SONAR_PRJ_KEY" /d:sonar.host.url="$SONAR_HOST" /d:sonar.login="$SONARQUBE_ACCESS_TOKEN" /d:sonar.verbose=true /d:sonar.scm.provider=git

RUN dotnet build "Infrastructure.ScoreCard.WebApi.csproj" -c Release
RUN dotnet publish "Infrastructure.ScoreCard.WebApi.csproj" -c Release -o /app/publish

RUN dotnet sonarscanner end /d:sonar.login="$SONARQUBE_ACCESS_TOKEN"

# Dotnet publish
#WORKDIR "/src/Infrastructure.ScoreCard.WebApi"
FROM build AS publish
RUN dotnet publish "Infrastructure.ScoreCard.WebApi.csproj" --no-restore -c Release -o /app/publish