Dotnet-sonarscanner version 8.0.0 hangs indefinitely

Our docker builds that use SonarQube (specifically through the dotnet-sonarscanner global tool) started hanging indefinitely after our base image cache expired and the latest version (8.0.0) started being picked up.

The problem happens when running the end command in a Docker container where the source code is at the root (.sln file at /, .csproj files under their respective folders). There is no error logged by the tool, it just seems to get stuck. We waited an hour in one case before cancelling the build.

Running again with verbose logs (/d:sonar.verbose=true) yields:

#21 [build 11/11] RUN dotnet sonarscanner end /d:sonar.token=***
#21 0.540 SonarScanner for MSBuild 8.0
#21 0.540 Using the .NET Core version of the Scanner for MSBuild
#21 0.614 Post-processing started.
#21 0.704 12:38:08.802  12:38:08.796  Uninstalling target: /.sonarqube/bin/targets/SonarQube.Integration.targets
#21 0.704 12:38:08.802  12:38:08.802  sonar.verbose=true was specified - setting the log verbosity to 'Debug'
#21 0.705 12:38:08.803  Loading the SonarQube analysis config from /.sonarqube/conf/SonarQubeAnalysisConfig.xml
#21 0.705 12:38:08.803  Not running under TeamBuild
#21 0.706 12:38:08.804  Analysis base directory: /.sonarqube
#21 0.706 Build directory: 
#21 0.706 Bin directory: /.sonarqube/bin
#21 0.706 Config directory: /.sonarqube/conf
#21 0.706 Output directory: /.sonarqube/out
#21 0.706 Config file: /.sonarqube/conf/SonarQubeAnalysisConfig.xml
#21 0.707 12:38:08.805  12:38:08.805  WARNING: Multi-Language analysis is enabled. If this was not intended, please set "/d:sonar.scanner.scanAll=false" in the begin step.
#21 0.790 12:38:08.888  Generating SonarQube project properties file to /.sonarqube/out/sonar-project.properties
#21 0.813 12:38:08.911  Setting analysis property: sonar.visualstudio.enable=false
#21 0.826 12:38:08.923  The supplied Code Analysis ErrorLog file is a valid json file and does not need to be fixed: /.sonarqube/out/1/Issues.json
#21 0.839 12:38:08.937  The supplied Code Analysis ErrorLog file is a valid json file and does not need to be fixed: /.sonarqube/out/0/Issues.json
#21 0.849 12:38:08.947  Using working directory as project base directory: '/'.

To be 100% clear, nothing else is logged after the last line above, we have to manually cancel the build.

As the files are already at the root, setting /d:sonar.projectBaseDir=/ does not work (it just complains that all files are outside the scan directory). Is there anything we can do besides sticking to the previous version?

Hi,

Could you provide debug logs, please?

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
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Thx,
Ann

Hi Ann,

The logs provided in the initial thread are the verbose logs for the END task.

The MS Build logs contain a lot of proprietary information that I cannot share publicly. I’m happy to look for anything in particular you need or send through a private channel.

To be clear, this was working perfectly fine with version 7.1.1.

Thanks,
Camilo

Hello @CamiloTerevinto

You ran into a known issue with the latest scanner version. You can find more details in this GitHub issue Root directory detection: OS root (`/` on Unix or `C:` on Windows) is identified as the project directory · Issue #2148 · SonarSource/sonar-scanner-msbuild · GitHub. A fix is already in place and will be released today.

Best, Martin

4 Likes

Hi @CamiloTerevinto,

As a workaround until the new version is released, you can set the /d:sonar.projectBaseDir= parameter in the scanner begin step. This will disable the automatic detection and will fix the hang.

1 Like

Hi Costin,

Thanks for the information, I was not entirely sure if that GitHub issue applied in this case or not.

I did try setting projectBaseDir=/ but that causes a massive amount of errors like

WARNING: File '/..../..DataWrapper.cs' is not located under the base directory '/.sonarqube/' and will not be analyzed.

Interesting, what is the value set for the sonar.projectBaseDir? It should point to the folder where your project sources are and not the .sonarqube directory.

The documentation can be found here: Analysis parameters

I tried with passing both projectBaseDir=/ and projectBaseDir=./ to the begin command. I got similar, if not the same, results. The last 3 lines of errors in both cases were:

#21 1.084 12:24:13.067  No analysable projects were found. SonarQube analysis will not be performed. Check the build summary report for details.
#21 1.084 12:24:13.067  Generation of the sonar-properties file failed. Unable to complete the analysis.
#21 1.087 12:24:13.07  Post-processing failed. Exit code: 1
  • Are all the source files in the projectBaseDir or in one of it’s nested folders?
  • Do you run the project build from the same folder from where you run the scanner begin step?
  • What operating system do you use? Is / pointing to the root of the file system (Unix) or current folder? If you’re not sure you can also provide the full path.

Martin just released a new version of the scanner but I’m not sure if your issue will be solved. You can give it a try.

If your project sources are really at the root of the file system, the scanner will try to analyze all the files and nested directories, starting with the root. This takes a long time and most probably it’s not what you want. You can disable this functionality by setting /d:sonar.scanner.scanAll=false in the begin step.

Having the verbose logs for both the begin and end step would help us to better understand the problem. You can sanitize them and remove all the sensitive information. And if you want I can DM you so we can have a private channel.

WARNING: File ‘/…/…DataWrapper.cs’

The error message makes me think that project base dir is set to one of the nested folders and not to the parent directory that contains all the source code. Could you try to set the projectBaseDir to an absolute path?

  • Are all the source files in the projectBaseDir or in one of it’s nested folders?
    Yes. The hierarchy looks like this:

/solution.sln
/project/project.csproj
/project/somefile.cs

  • Do you run the project build from the same folder from where you run the scanner begin step?
    Yes, all commands are run from the base (/) path.

  • What operating system do you use?
    This is all run on a Docker container, the base image is Ubuntu 22.04. / is the root of the file system.

I will give a try with the new version tomorrow and let you know how it goes.


Could you try to set the projectBaseDir to an absolute path?
I am not sure what would be the absolute path for the root path other than /

Hey Costin, I was able to get 8.0.1 to work only after setting /d:sonar.scanner.scanAll=false as part of the begin step.

We’ll look at moving the files away from the root directory later and turn that new feature on.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.