Running dotnet sonarscanner in TeamCity fails with "Post-processing failed"

We use a Github repository for our source control, with the code being built via TeamCity, where we had previously set up SonarScanner to upload to SonarCloud for our repositories, but we have now learned that we would need to do it differently to upload C# code, which is the majority of our projects.

We previously used a SonarScanner command like this to upload our build, performed in the solution directory:

sonar-scanner.bat -D"sonar.organization=star-code" -D"sonar.projectKey=STAR-Code_Borgerindsats" -D"sonar.sources=." -D""

This worked without issue, and we have uploaded the code SonarCloud.

We now try to do the same using the dotnet SonarScanner instead, using these commands, performed in the solution directory:

Write-Info "Starting Sonar Step"

Write-Info "Where JAVA"
where java

Write-Info "Java Version"
D:\SonarScanner\jre\bin\java.exe --version

Write-Info "Start Sonar Scanner"
dotnet sonarscanner begin `
    /k:"STAR-Code_Borgerindsats" `
    /o:"star-code" `
    /d:sonar.login="$Env:SONAR_TOKEN" `
    /"" `
    /"2024-1/master" `

$msbArgs = "build Star.Borgerindsats.sln --configuration $configuration --nologo";

Write-Info "Build Solution"
RunDotnet -Arguments $msbArgs -WorkingDir $slnDir

Write-Info "End Sonar Scanner"
dotnet sonarscanner end /d:sonar.login="$Env:SONAR_TOKEN"

Write-Info "Ending Sonar Step"

but when we do, we get the following error message in TeamCity, nothing is uploaded to SonarCloud and no background task is created where I could see an analysis ID:

[05:28:34][Step 2/2] 2024-01-08 05:28:34,197 [INFO ] End Sonar Scanner  
[05:28:36][Step 2/2] The SonarScanner did not complete successfully
[05:28:40][Step 2/2] Error message: The SonarScanner did not complete successfully
[05:28:36][Step 2/2] 05:28:36.273  Post-processing failed. Exit code: 1
[05:28:36][Step 2/2] 2024-01-08 05:28:36,332 [INFO ] Ending Sonar Step

It seems like the error occurs in the dotnet sonarscanner end command.

We are still using the same SonarCloud project that we used to upload with our original upload.
Should we delete it and import the project from GITHUB again, or is there something else wrong with our SonarScanner commands?

We have found the solution to this issue, it seems like the paths had not loaded properly on the build servers.

1 Like

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