Issue with donetsonarscanner on Windows Gitlab runner

Hi team,

I’m facing a weird issue on dotnetsonarscanner -

  • Use SonarCloud version for tracking projects.
  • ALM used (Gitlab)
  • CI system used (Gitlab CI with Windows Gitlab Runner on AWS EC2)
  • Java version on runner - 17.0.8 LTS 211
  • Dotnetsonarscanner - 5.13.0 / 6.2.0
  • Scanner command is invoked with below powershell script snippet -
if ([string]::IsNullOrEmpty("$env:CI_MERGE_REQUEST_IID"))
{
    & echo "Running Branch analysis"
    & dotnet sonarscanner begin /k:"$SonarProjectKey" /o:"$SonarOrganization" /d:sonar.token="$SonarToken" `
          /d:sonar.host.url="$env:SONAR_HOST_URL" `
          /d:sonar.qualitygate.wait=true `
          /d:sonar.branch.name="$env:CI_COMMIT_BRANCH"
}
else
{
    & echo "Running SQ Merge Request analysis"
    & dotnet sonarscanner begin /k:"$SonarProjectKey" /o:"$SonarOrganization" /d:sonar.token="$SonarToken" `
          /d:sonar.host.url="$env:SONAR_HOST_URL" `
          /d:sonar.qualitygate.wait=true `
          /d:sonar.pullrequest.key="$env:CI_MERGE_REQUEST_IID" `
          /d:sonar.pullrequest.branch="$env:CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" `
          /d:sonar.pullrequest.base="$env:CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
}

& "$env:MSBUILD_PATH" "$env:CI_PROJECT_DIR\src\Presentation\myproject.Presentation.UI\myproject.Presentation.UI.csproj"`
    /p:Configuration=Release # build the project
& dotnet sonarscanner end /d:sonar.token="$SonarToken"
  • Languages of the repository - C#/.Net
  • Error observed
C:\Builds\drWJzxxF\1\path_to_my_project\src\Presentation\myproject.Presentation.UI\Helpers\CookieManager.cs(19,30): warning S3330: Make sure creating this cookie without the "HttpOnly" flag is safe. [C:\Builds\drWJzxxF\1\path_to_my_project\src\Presentation\myproject.Presentation.UI\myproject.Presentation.UI.csproj]

    630 Warning(s)
    0 Error(s)

Time Elapsed 00:01:33.61
SonarScanner for MSBuild 6.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI...
INFO: Scanner configuration file: C:\Users\Administrator\.dotnet\tools\.store\dotnet-sonarscanner\6.2.0\dotnet-sonarscanner\6.2.0\tools\netcoreapp3.1\any\sonar-scanner-5.0.1.3006\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\Builds\drWJzxxF\1\path_to_my_project\src\.sonarqube\out\sonar-project.properties
INFO: SonarScanner 5.0.1.3006
INFO: Java 17.0.8 Oracle Corporation (64-bit)
INFO: Windows Server 2019 10.0 amd64
INFO: User cache: C:\Users\Administrator\.sonar\cache
INFO: Analyzing on SonarCloud
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=501ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: Loading required plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=966ms
INFO: Load/download plugins
INFO: Load/download plugins (done) | time=1350ms
INFO: Found an active CI vendor: 'Gitlab CI'
INFO: Load project settings for component key: 'myproject_all_sitecore-backend'
INFO: Load project settings for component key: 'myproject_all_sitecore-backend' (done) | time=296ms
INFO: Process project properties
INFO: Project key: myproject_all_sitecore-backend
INFO: Base dir: C:\Builds\drWJzxxF\1\path_to_my_project\src
INFO: Working dir: C:\Builds\drWJzxxF\1\path_to_my_project\src\.sonarqube\out\.sonar
INFO: Load project branches
INFO: Load project branches (done) | time=874ms
INFO: Check ALM binding of project 'myproject_all_sitecore-backend'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'myproject_all_sitecore-backend' (done) | time=847ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=912ms
INFO: Load branch configuration
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 15.589s
INFO: Final Memory: 10M/40M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator to check the permissions of the user the token belongs to
ERROR: 
The SonarScanner did not complete successfully
00:38:09.023  Post-processing failed. Exit code: 1
ExitError : Sonar Quality analysis failed.
At 
C:\Builds\drWJzxxF\1\path_to_my_project\ci\scripts\run-sonarscanner.ps1:41 
char:1
+ ExitError "Sonar Quality analysis failed." -ExitCode $LastExitCode -S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,ExitError
 
section_end:1717720689:step_script
[0Ksection_start:1717720689:cleanup_file_variables
[0K[0K[36;1mCleaning up project directory and file based variables[0;m[0;m
section_end:1717720690:cleanup_file_variables
[0K[31;1mERROR: Job failed: exit status 1
[0;m
  • Getting reproduced everytime sonar scanner job runs.
  • Potential workaround - NONE
  • It was all working well until after May 29, 2024. No change was made anywhere in the Sonar setup or CI pipeline or Gitlab runner. It started failing suddenly.
  • Build job and deploy jobs work seamlessly. Only sonar job is failing. So, we can rule out Gitlab runner problem.
  • Followed commands from [Link] (SonarScanner for .NET)
  • What has been done - triple-checked token permissions, reissued tokens, reran pipelines multiple times with new tokens, reran after clearing runner cache, reverified, org key, project key and sonar tokens by printing then in log files temporarily (especially token).

Can someone please help? Really at a loss on where to look for the fix.

Appreciate any help.

Thanks,
Abhijit

Hey there.

Can you check your organization-level Administration > Organization Settings > GitLab connectivity management and supply a new token if needed?

1 Like

Hi there!

Yes! That was the reason indeed.

I have supplied a new PAT from Gitlab. It’s working like a charm now.

Thanks for your help!! Much appreciated.

Thanks,
Abhijit