SonarQube - * Version 8.9 (build 43852)
Scanner used from Azure DevOps extension in MSBuild mode
I have a project that is a combination of typescript (cdk) and also a .net solution and projects.
I am using Azure DevOps as a ci tool and trying to analyse the project as a whole.
I am use the Azure DevOps Sonar extension.
Using this in cli mode, I am able to successfully scan the whole project, but as expected, it ignores the c# files.
Using MSBuild mode, I am able to succesfully scan the c# solution and projets, but then none of my typescript code gets analysed.
I have read in a few blog posts that we can create a C# project that exists purely to include all of the other none .net files. However this results in warnings saying they will be excluded due to not being in the default base directory detected by the scanner.
As a test, i decided to just use the global .net scanner directly (i.e not the extension) and with the following it worked, and included scanning all my files:
- task: PowerShell@2
displayName: SonarQube DotNet Core Scan
inputs:
targetType: inline
script: |
$sourceBranchName = "$(Build.SourceBranch)"
Write-Host "Source branch name is $sourceBranchName"
$branchName = $sourceBranchName.Replace("refs/heads/","")
dotnet tool install --global dotnet-sonarscanner
dotnet sonarscanner begin /k:"com.shell.$(Build.DefinitionName)" /d:sonar.branch.name="$branchName" /d:sonar.login="$(SonarQubeToken)" /d:sonar.host.url="$(SonarQubeURL)" /d:sonar.projectBaseDir="$(System.DefaultWorkingDirectory)/$(Build.Repository.Name)"
dotnet build $(System.DefaultWorkingDirectory)/$(Build.Repository.Name)/Api/Test/Test.sln
dotnet sonarscanner end /d:sonar.login="$(SonarQubeToken)"
However, the issue with this is my results dont get published to ADO as part of the build result.
So went back to use teh ADO extension, and I got the scan working properly for .net core - however i was back to only getting the c# files analysed.
This time, when i tried to specify the base directory, as i did in the above example. It now results in a whole bunch of errors.
config that works but only scans c# files
- task: SonarQubePrepare@5
inputs:
SonarQube: 'Shell Energy Sonarqube'
scannerMode: 'MSBuild'
projectKey: 'com.shell.rtl-market-nmi-discovery-service'
extraProperties: |
sonar.exclusions=$(Exclusions)
- template: build-templates/dotnet-build-pipeline.yml
parameters:
DefaultWorkingDirectory: ${{ variables.DefaultWorkingDirectory }}
PathToProjects: ${{ variables.PathToProjects }}
outputPath: ${{ variables.outputPath }}
- task: SonarQubeAnalyze@5
- task: SonarQubePublish@5
config that should work similar to my first exapmle but throws errors instead
- task: SonarQubePrepare@5
inputs:
SonarQube: 'Shell Energy Sonarqube'
scannerMode: 'MSBuild'
projectKey: 'com.shell.rtl-market-nmi-discovery-service'
extraProperties: |
sonar.exclusions=$(Exclusions)
sonar.projectBaseDir="$(System.DefaultWorkingDirectory)/$(Build.Repository.Name)"
- template: build-templates/dotnet-build-pipeline.yml
parameters:
DefaultWorkingDirectory: ${{ variables.DefaultWorkingDirectory }}
PathToProjects: ${{ variables.PathToProjects }}
outputPath: ${{ variables.outputPath }}
- task: SonarQubeAnalyze@5
- task: SonarQubePublish@5
The errors that i am seeing look like this:
##[error]00:45:30.687 ERROR: Error during SonarScanner execution
##[debug]Processed: ##vso[task.logissue type=error;]00:45:30.687 ERROR: Error during SonarScanner execution
00:45:30.687 ERROR: Error during SonarScanner execution
##[error]java.lang.IllegalStateException: Error when resolving baseDir
##[debug]Processed: ##vso[task.logissue type=error;]java.lang.IllegalStateException: Error when resolving baseDir
java.lang.IllegalStateException: Error when resolving baseDir
##[error]at org.sonarsource.scanner.cli.Conf.loadModuleConfigFile(Conf.java:190)
at org.sonarsource.scanner.cli.Conf.loadModulesProperties(Conf.java:162)
at org.sonarsource.scanner.cli.Conf.loadProjectProperties(Conf.java:136)
at org.sonarsource.scanner.cli.Conf.properties(Conf.java:61)
at org.sonarsource.scanner.cli.Main.execute(Main.java:69)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
##[debug]Processed: ##vso[task.logissue type=error;]at org.sonarsource.scanner.cli.Conf.loadModuleConfigFile(Conf.java:190)%0A at org.sonarsource.scanner.cli.Conf.loadModulesProperties(Conf.java:162)%0A at org.sonarsource.scanner.cli.Conf.loadProjectProperties(Conf.java:136)%0A at org.sonarsource.scanner.cli.Conf.properties(Conf.java:61)%0A at org.sonarsource.scanner.cli.Main.execute(Main.java:69)%0A at org.sonarsource.scanner.cli.Main.main(Main.java:61)
at org.sonarsource.scanner.cli.Conf.loadModuleConfigFile(Conf.java:190)
at org.sonarsource.scanner.cli.Conf.loadModulesProperties(Conf.java:162)
at org.sonarsource.scanner.cli.Conf.loadProjectProperties(Conf.java:136)
at org.sonarsource.scanner.cli.Conf.properties(Conf.java:61)
at org.sonarsource.scanner.cli.Main.execute(Main.java:69)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
##[error]Caused by: java.nio.file.NoSuchFileException: /home/vsts/work/1/"/home/vsts/work/1/s/rtl-market-nmi-discovery-service"
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.isSameFile(UnixFileSystemProvider.java:337)
##[debug]Processed: ##vso[task.logissue type=error;]Caused by: java.nio.file.NoSuchFileException: /home/vsts/work/1/"/home/vsts/work/1/s/rtl-market-nmi-discovery-service"%0A at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)%0A at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)%0A at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)%0A at java.base/sun.nio.fs.UnixFileSystemProvider.isSameFile(UnixFileSystemProvider.java:337)
Caused by: java.nio.file.NoSuchFileException: /home/vsts/work/1/"/home/vsts/work/1/s/rtl-market-nmi-discovery-service"
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.isSameFile(UnixFileSystemProvider.java:337)
##[error]at java.base/java.nio.file.Files.isSameFile(Files.java:1531)
at org.sonarsource.scanner.cli.Conf.loadModuleConfigFile(Conf.java:186)
… 5 more
##[debug]Processed: ##vso[task.logissue type=error;]at java.base/java.nio.file.Files.isSameFile(Files.java:1531)%0A at org.sonarsource.scanner.cli.Conf.loadModuleConfigFile(Conf.java:186)%0A … 5 more
at java.base/java.nio.file.Files.isSameFile(Files.java:1531)
at org.sonarsource.scanner.cli.Conf.loadModuleConfigFile(Conf.java:186)
… 5 more
i can see that this
##[error]Caused by: java.nio.file.NoSuchFileException: /home/vsts/work/1/"/home/vsts/work/1/s/rtl-market-nmi-discovery-service"
is not a vald path, so i tried changing my base dir that was passing in to make this path look valid, but that only results in teh root directory again being assumed as the project solution directory which excludes all of my extra files again. I am trying to understand why this behaviour is different