Have a docker image that just gives us .NET 8 and dotnet-sonarscanner
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
#Begin Sonar
RUN dotnet tool install --global dotnet-sonarscanner --version 5.3.1
ENV PATH="${PATH}:/root/.dotnet/tools"
In our jenkins file we docker inside
and run dotnet sonarscanner build
dockerImageSonar = docker.image('above-image')
dockerImageSonar.inside("-v $WORKSPACE:/app -e SONAR_HOST_URL='https://sonarcloud.io' -e SONAR_TOKEN=${SONAR_TOKEN} -e BRANCH_NAME=${branch} -e CHANGE_BRANCH=${changeBranch} -e CHANGE_ID=${changeId} -e CHANGE_TARGET=${changeTarget} -u 0:0")
{
sh """
dotnet tool list -g
mkdir -p ${fileDirectory}/tests/
find / -type d -name "StrykerOutput" -exec cp -avr --target-directory=${fileDirectory}/tests/ {} +
echo 'Sonar PR CHANGE_BRANCH : ${changeBranch}'
dotnet-sonarscanner begin /k:${applicationName} /d:sonar.pullrequest.branch=${changeBranch} /d:sonar.pullrequest.base=${changeTarget} /d:sonar.login=${SONAR_TOKEN} /d:sonar.cs.opencover.reportsPaths='**/TestResults/coverage.opencover.xml' /d:sonar.coverage.exclusions='**Tests*.cs' /d:sonar.verbose=true
dotnet build ${projectPath} -c release
ls -F
dotnet-sonarscanner end /d:sonar.login=${SONAR_TOKEN}
"""
}
however we get the following error
+ dotnet tool list -g
Package Id Version Commands
---------------------------------------------------------
dotnet-sonarscanner 5.3.1 dotnet-sonarscanner
+ mkdir -p src/Opshub.Withdrawals.Service/tests/
+ find / -type d -name StrykerOutput -exec cp -avr --target-directory=src/Service/tests/ {} +
+ dotnet-sonarscanner begin /k:service-name
/d:sonar.pullrequest.branch=feature/work /d:sonar.pullrequest.base=master /d:sonar.cs.opencover.reportsPaths=**/TestResults/coverage.opencover.xml /d:sonar.coverage.exclusions=**Tests*.cs /d:sonar.verbose=true
You must install or update .NET to run this application.
App: /root/.dotnet/tools/dotnet-sonarscanner
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '5.0.0' (x64)
.NET location: /usr/share/dotnet
The following frameworks were found:
8.0.0 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]
If you see from the dotnet tool list
command it has dotnet-sonarscanner but it doesn’t seem to be happy with .net 8
This previously worked with .net 6