Dotnet sonarqube not running for loop for build command

Problem: Using FOR Loop to cycle through array of build commands actually does nothing.

I have the dotnet-sonarscanner working if I do not use the FOR Loop.

Now, I want the ability to run multiple build commands after the “dotnet sonarscanner begin…” command. This way Sonarqube will scan the whole project.

I use a Powershell script to run all the commands. This currently works:

  • dotnet test …
  • dotnet build-server shutdown
  • dotnet sonarscanner begin
  • dotnet build
  • dotnet sonarscanner end

This does not work

  • dotnet test …
  • dotnet build-server shutdown
  • dotnet sonarscanner begin
  • FOR Loop (loop through array of build commands)
    {
    dotnet build
    }
  • dotnet sonarscanner end

There is zero output from the FOR Loop. and then “dotnet sonarscanner end” fails since there is no analysis.

This even happens if I only have 1 solution file in the array. It seems Sonarqube will not let the FOR Loop execute. It seems it wants the next command to be dotnet build …

I am running this version:

Package Id Version Commands

dotnet-sonarscanner 4.10.0 dotnet-sonarscanner

Hello @Sonarroma,

What you indicate in your report seems not because of the SonarScanner itself. The scanner has nothing to do with what happen in:

FOR Loop (loop through array of build commands)
{
  dotnet build
}

The scanner supports multiple project being built between Begin and End steps. Have you tried by explicitly listing all all project build commands to make sure it works:

dotnet sonarscanner begin
dotnet build project1
dotnet build project2
dotnet build project3
dotnet sonarscanner end

Finally, what happen if you keep the for loop without scanner commands? Does it build your projects?

Cheers