What value do I use for sonar.projectBaseDir?

  • SonarQube 8.6.0.39681
  • SonarScanner for MSBuild 5.0.4

NOTE: This warning does not appear for the full build. Just the PR builds.

Originally I get this warning in SonarQube:

SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.

In order to fix this error I set the ‘sonar.scm.provider=git’.
But then I get the error:

Not inside a Git work tree: D:\a\1\s

To fix that I have tried to set the ‘sonar.projectBaseDir’ but I cannot find the format to set.
If I use $(Build.SourcesDirectory) the build fails with:

[error]java.nio.file.InvalidPathException: Illegal char <:> at index 2: 'D:\a\1\s\'

I have tried many different formats…

D:\a\1\s\My.Repo.Dir  <-- yes, my repo dir contains dots
D:/a/1/s/
D/a/1/s/
d/a/1/s/My.Repo.Dir
..\..\..\s\My.Repo.Dir\  (This was based on the Project root configuration file being here: D:\a\1\.sonarqube\out\sonar-project.properties)
/My.Repo.Dir/
My.Repo.Dir/

… and all of them get an error of either

[error]java.nio.file.InvalidPathException: Illegal char <:> at index 2: 'D:\a\1\s\'

… or …

[error]java.lang.IllegalStateException: Error when resolving baseDir

What format should baseDir take? Is there a way to use the Windows paths and not get the error?
Basically, what am I doing wrong and how do I fix it?

Hi,

You shouldn’t need to set sonar.projectBaseDir. It’s only needed in unusual situation. Generally you should kick analysis off from the project root directory, which will naturally put you in the directory where analysis expects to find the SCM data.

Also generally, if analysis doesn’t automatically detect your SCM flavor &etc, then manually setting a flavor with sonar.scm.provider isn’t going to help. TBH, I’m not sure it ever did, & we should re-visit that advice. (I’ll be referring that internally.)

So. This started from SCM provider autodetection failed. If we back up to that, then the question is why autodetection failed. Are you analyzing from project root, or do you cd down in the structure before kicking off analysis?

 
Ann

If we’re going to “back up to the start” it started with this error in my PR builds:
Could not find ref ‘‘refs/heads/development’’ in refs/heads, refs/remotes/upstream or refs/remotes/origin. You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis.

So, I added a checkout of the root branch to the pipeline. Then I started getting the SCM error. So I added that. Then I got the error I posted here.

I don’t explicitly change the directory, no. I added Get-Location calls between tasks and don’t see any change all the way through the pipeline.

Hi,

These may be helpful:

 
Ann

Thanks but I didn’t find anything in those. They looked like they were unfixed as well.

That said I have tried a few things and cannot change the Pipeline.Workspace at all. In fact I’ve gotten an error that said Pipeline.Workspace cannot be changed.

So, it looks like the only way to change the working directory is within the task itself. I have no idea how to change the current directory. Should I run the analysis from a powershell task? That would allow me to set the workingDirectory.

Hi,

This

is about the scanner not being able to find in your SCM what you’ve asked it to analyze. Often this is caused by your CI auto/“helpfully” doing a merge commit on the PR early in the process.

 
Ann

Thank you, that is interesting.

Currently I’m passing
sonar.pullrequest.base='refs/heads/development'
… and …
sonar.pullrequest.branch='refs/heads/Feature/changedBranch'

Should I modify this? Or is there a way to get Azure to not merge commit until a certain point?