We use a series of templates to build and deploy in ADO. We have a section that allows passing of additional tasks into the templates. I am trying to pass in the sonarcloud tasks but this does not work because it doesn’t like the directory that our code lives in (which is a result of checking out multiple repos, including the templates)
This SonarCloudAnalyze task fails with the following
15:21:01.082 WARNING: File ‘/home/vsts/work/1/code/redacted-demo/Program.cs’ is not located under the base directory ‘/home/vsts/work/1/s’ and will not be analyzed.
15:21:01.082 WARNING: File ‘/home/vsts/work/1/code/redacted-demo/obj/Debug/net8.0/apphost’ is not located under the base directory ‘/home/vsts/work/1/s’ and will not be analyzed.
Is it possible to use sonarcloud as part of our templates? I have been going round in circles and tested a number of things without success, so any help you be appreciated.
Then only the files associated with these .csproj files will be indexed and analyzed automatically by the SonarScanner for .NET. There’s no need to specify them separately with sonar.sources.
How does analysis behave when you remove sonar.sources?
09:47:09.4 WARNING: File ‘/home/vsts/work/1/code/redacted-demo/Program.cs’ is not located under the base directory ‘/home/vsts/work/1/s’ and will not be analyzed.
09:47:09.401 WARNING: File ‘/home/vsts/work/1/code/redacted-demo/obj/Debug/net8.0/apphost’ is not located under the base directory ‘/home/vsts/work/1/s’ and will not be analyzed.
You could also try playing around with sonar.projectBaseDir (the same way you were configuring sonar.sources under SonarQubePrepare) to see if you ultimately get a correct value.
I would guess it wants to be /home/vsts/work/1/ or /home/vsts/work/1/code/.
In fact, diving into the code, I’m pretty sure this is what you want to be doing. The SonarScanner for .NET will use Build.SourcesDirectory if not told otherwise, which seems to be the wrong directory in your multi-repo checkout scenario. One of these variables must be a better one.
I’m trying to do some python with the same logic but it doesn’t appear to scanning the files. I will keep trying and then if I get stuck I’ll reach out again.