Azure DevOps SonarQube Buildstep Plugin needs adaptable projectBaseDir when using MSBuild

When using SonarQubePrepare@5 buildstep in an Azure DevOps Server yaml pipeline definition the SonarQube scanner will ignore the projectBaseDir property when using the MSBuild scanner and seems to always assume Build.SourcesDirectory or System.DefaultWorkingDirectory (not sure since both are always the same). This might be ok for most scenarios, but with Microsoft build agent 3.231 there’ll be a new feature that allows you to check out repositories anywhere below the Agent.WorkFolder directory. This is so you can use centralized repositories that save a lot of space with multiple pipelines on self hosted agents. But when you check them out the a directory like say “C:\agent_work\Repositories\MyRepo” instead of “C:\agent_work\1\s” this won’t work since Microsoft doesn’t adapt the Build.SourcesDirectory or System.DefaultWorkingDirectory variables accordingly. Which means just assuming those variables are correct does no longer work in those scenarios since none of the source files will be below the “base directory” of “C:\agent_work\1\s”.

What we need here is the possibility to set the projecteBaseDir for MSBuild scanner projects to something different from the default, or else this feature cannot be used with SonarQube.

See this pull request here with which this feature was pulled into the agent master branch and where I’m again mentioning the problem with the SonarQube build step: https://github.com/microsoft/azure-pipelines-agent/pull/4423#issuecomment-1777446426

I’ve also already opened an issue here once about this, before the feature was in the agent. So I’m opening a new issue here so you know it’s kinda urgent now. Here’s the link to the old issue: Ability to set working directory for MSBuild Sonar Scanner in Azure DevOps Server extension

2 Likes

Hello @echalone,

Thank you for reporting this issue.

Sorry for the delay, this issue triggered internal discussions.

I understand the impact, it would help me a lot if you were able to give more details on how exactly you use this feature alongside SonarScanner for .NET.

I would need from you the following:

  • your yaml configuration for the SonarQubePrepare@5 step with the usage of the sonar.projectBaseDir option
  • the complete log of the executed SonarQubePrepare@5 step in verbose mode (see how below)

Thank you!

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true