I am getting an error on the following Dockerfile line:
RUN dotnet sonarscanner end /d:sonar.login=“$SONAR_TOKEN”
I am not sure what to check. See details below.
- ALM: None
- CI system: None
- Scanner command used: RUN dotnet sonarscanner end /d:sonar.login=“$SONAR_TOKEN”
- Languages of the repository: C#
- Error observed: => ERROR [build 12/12] RUN dotnet sonarscanner end /d:sonar.login=“[redacted]”
- Potential workaround: Unknown
- Steps to reproduce:
- Upload project to sonarsoource.
- Install docker and docker desktop
- Install WSL 2 (with Ubuntu)
- Get internet connection working with WSL 2
- In Ubuntu, navigate to the directory with the attached source code. Mine is the following:
/mnt/c/src/dev/spike/layoutboards/layoutboards
- In Ubuntu, Run the following from where the solution file is:
docker build -t layoutbourds .
Results: ERROR [build 12/12] RUN dotnet sonarscanner end /d:sonar.login=“[redacted]”
Expected results: Successfully completes and updates SonarSource.
Logs:
csteague7@DESKTOP-RII0P02:/mnt/c/src/dev/spike/layoutboards/layoutboards$ docker build -t layoutbourds .
[+] Building 23.9s (18/20) docker:default
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 1.96kB 0.1s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/core/aspnet:3.1 0.6s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0 0.6s
=> [build 1/12] FROM mcr.microsoft.com/dotnet/sdk:6.0@sha256:6e736983e406ac0092372af2470ad6dbfdbf04280d4c5bc866752db8f8c4d5b4 0.0s
=> [stage-1 1/3] FROM mcr.microsoft.com/dotnet/core/aspnet:3.1@sha256:e3b773f30a0a6e88d71ce52429f6847627fc9353e491346902ca34576 0.0s
=> [internal] load build context 2.7s
=> => transferring context: 32.31kB 2.7s
=> CACHED [build 2/12] WORKDIR /app 0.0s
=> CACHED [build 3/12] RUN apt-get update && apt-get install -y openjdk-11-jdk 0.0s
=> CACHED [build 4/12] RUN dotnet tool install --global dotnet-sonarscanner 0.0s
=> CACHED [build 5/12] RUN dotnet tool install --global coverlet.console 0.0s
=> [build 6/12] COPY . . 0.0s
=> [build 7/12] RUN dotnet restore 3.0s
=> [build 8/12] RUN dotnet sonarscanner begin /k:"Dynastyse_layoutboards" /o:"dynastyse" /d:sonar.host.url="https://son 10.0s
=> [build 9/12] COPY . . 0.1s
=> [build 10/12] RUN dotnet publish --output /out/ 3.4s
=> [build 11/12] RUN dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="/coverage" 2.0s
=> ERROR [build 12/12] RUN dotnet sonarscanner end /d:sonar.login="98b5f14bc1b750bfafef58e7d1cec16c2a3a3e8f" 1.9s
------
> [build 12/12] RUN dotnet sonarscanner end /d:sonar.login="98b5f14bc1b750bfafef58e7d1cec16c2a3a3e8f":
1.680 SonarScanner for MSBuild 6.0
1.680 Using the .NET Core version of the Scanner for MSBuild
1.718 Post-processing started.
1.793 Calling the SonarScanner CLI...
1.840 Error: LinkageError occurred while loading main class org.sonarsource.scanner.cli.Main
1.840 java.lang.UnsupportedClassVersionError: org/sonarsource/scanner/cli/Main has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
1.876 The SonarScanner did not complete successfully
1.876 23:45:26.72 Post-processing failed. Exit code: 1
------
Dockerfile:44
--------------------
42 |
43 | # End Sonar Scanner
44 | >>> RUN dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"
45 |
46 | #######################################################
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\"" did not complete successfully: exit code: 1
csteague7@DESKTOP-RII0P02:/mnt/c/src/dev/spike/layoutboards/layoutboards$
Dockerfile:
#######################################################
# Step 1: Build the application in a container #
#######################################################
# Download the official ASP.NET Core SDK image
# to build the project while creating the docker image
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG SONAR_PROJECT_KEY=[redacted]
ARG SONAR_OGRANIZAION_KEY=[redacted]
ARG SONAR_HOST_URL=https://sonarcloud.io
ARG SONAR_TOKEN=[redacted]
WORKDIR /app
# Install Sonar Scanner, Coverlet and Java (required for Sonar Scanner)
RUN apt-get update && apt-get install -y openjdk-11-jdk
RUN dotnet tool install --global dotnet-sonarscanner
RUN dotnet tool install --global coverlet.console
ENV PATH="$PATH:/root/.dotnet/tools"
# Start Sonar Scanner
RUN dotnet sonarscanner begin \
/k:"$SONAR_PROJECT_KEY" \
/o:"$SONAR_OGRANIZAION_KEY" \
/d:sonar.host.url="$SONAR_HOST_URL" \
/d:sonar.login="$SONAR_TOKEN" \
/d:sonar.cs.opencover.reportsPaths=/coverage.opencover.xml
# Restore NuGet packages
COPY . .
RUN dotnet restore
# Copy the rest of the files over
COPY . .
# Build and test the application
RUN dotnet publish --output /out/
RUN dotnet test \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=opencover \
/p:CoverletOutput="/coverage"
# End Sonar Scanner
RUN dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"
#######################################################
# Step 2: Run the build outcome in a container #
#######################################################
# Download the official ASP.NET Core Runtime image
# to run the compiled application
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
# Open port
EXPOSE 8080
# Copy the build output from the SDK image
COPY --from=build /out .
# Start the application
ENTRYPOINT ["dotnet", "MyApp.dll"]