Must-share information (formatted with Markdown):
- Using dotnet-sonarscanner 9.0.2 installed via
dotnet tool update dotnet-sonarscanner
- Running the scan in a GitHub Action, docker runner. Java and dotnet were set up via their respective setup actions directly from github.
The dotnet-sonarscanner is installed via
mkdir -p .sonar/scanner
dotnet tool update dotnet-sonarscanner --tool-path .sonar/scanner
echo "[runner/working/directory]/.sonar/scanner" >> $GITHUB_PATH
The working directory in the runner is the base repo directory after doing a simple actions/checkout
run. Everything is run from within this root directory of the repo.
Workflow is as follows:
First, set do the begin on the scanner:
dotnet-sonarscanner begin /k:"[name]" \
/s:"[runner/working/directory]/SonarQube.Analysis.xml" \
/d:sonar.token=$SONAR_TOKEN \
/d:sonar.buildbreaker.skip=true \
/d:sonar.qualitygate.wait=true \
SonarQube.Analysis.xml
contains:
<SonarQubeAnalysisProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">
<Property Name="sonar.cs.opencover.reportsPaths">**/TestResults/**/coverage.opencover.xml</Property>
<Property Name="sonar.host.url">[on-prem URL]</Property>
<Property Name="sonar.projectBaseDir">.</Property>
<Property Name="sonar.projectKey">[project key]</Property>
<Property Name="sonar.qualitygate.wait">true</Property>
<Property Name="sonar.verbose">false</Property>
<Property Name="sonar.exclusions">.github/actions/**/*.js</Property>
</SonarQubeAnalysisProperties>
Then we run a build and test with dotnet test [solution]
Finally finishing the scan with dotnet-sonarscanner end /d:sonar.token=$SONAR_TOKEN
With version 9.0.1, the call to end
processes as expected, with version 9.0.2, we get this error for every file in solution which was being scanned:
15:38:23.418 WARNING: File '[runner/working/directory]/src/Component/File1.cs' is not located under the base directory '[runner/working/directory]/.sonarqube' and will not be analyzed.
15:38:23.418 WARNING: File '[runner/working/directory]/src/Component/File2.cs' is not located under the base directory '[runner/working/directory]/.sonarqube' and will not be analyzed.
15:38:23.418 WARNING: File '[runner/working/directory]/src/Component/File3.cs' is not located under the base directory '[runner/working/directory]/.sonarqube' and will not be analyzed.
15:38:23.418 WARNING: File '[runner/working/directory]/src/Component/File4.cs' is not located under the base directory '[runner/working/directory]/.sonarqube' and will not be analyzed.
...
15:38:23.422 Generation of the sonar-properties file failed. Unable to complete the analysis.
15:38:23.425 Post-processing failed. Exit code: 1
It seems that what sonar.projectBaseDir
is pointing to in 9.0.2 has changed vs 9.0.1. This seems like a bug for a patch release IMO. In 9.0.1 it is pointing at the directory in which begin
call was made, in 9.0.2 it appears to be the tool directory.