Sonar script failing with Response status code does not indicate success: 403 () on gitlab CICD

  • ALM used -GitLab
  • CI system -Gitlab
  • Scanner command used when applicable - ‘’‘dotnet-sonarscanner begin /k:“${CI_PROJECT_ROOT_NAMESPACE}_${CI_PROJECT_NAME}” /o:“${CI_PROJECT_ROOT_NAMESPACE}” /d:sonar.token=“${SONAR_TOKEN}” /d:sonar.host.url=“${SONAR_HOST_URL}” /d:sonar.qualitygate.wait=true /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml ‘’’
  • Languages of the repository - Dot Net
  • Only if the SonarCloud project is public, the URL
    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed ‘’‘Failed to request and parse ‘https://sonarcloud.io/api/qualityprofiles/search?project=XYZ_PROJECTNAME&organization=XYZ’: Response status code does not indicate success: 403 ()
    Unhandled exception. System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 ().
    at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
    at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
    at SonarScanner.MSBuild.PreProcessor.WebClientDownloader.TryDownloadIfExists(Uri url, Boolean logPermissionDenied)
    at SonarScanner.MSBuild.PreProcessor.SonarWebService.<>c__DisplayClass7_0.<b__0>d.MoveNext()
    — End of stack trace from previous location —
    at SonarScanner.MSBuild.PreProcessor.SonarWebService.ExecuteWithLogs[T](Func1 request, Uri logUri) at SonarScanner.MSBuild.PreProcessor.SonarWebService.TryGetQualityProfile(String projectKey, String projectBranch, String organization, String language) at SonarScanner.MSBuild.PreProcessor.PreProcessor.FetchArgumentsAndRuleSets(ISonarWebService server, ProcessedArgs args, BuildSettings settings) at SonarScanner.MSBuild.PreProcessor.PreProcessor.DoExecute(ProcessedArgs localSettings) at SonarScanner.MSBuild.PreProcessor.PreProcessor.Execute(IEnumerable1 args)
    at SonarScanner.MSBuild.BootstrapperClass.PreProcess()
    at SonarScanner.MSBuild.BootstrapperClass.Execute()
    at SonarScanner.MSBuild.Program.Execute(String args, ILogger logger)
    at SonarScanner.MSBuild.Program.Execute(String args)
    at SonarScanner.MSBuild.Program.Main(String args)
    at SonarScanner.MSBuild.Program.(String args) ‘’’

Same script was working in the previous pipelines but recently we observed that the sonar is failing with the above errors. We tried updating the security token but still the error is the same. Can you please share your inputs.

Hey there

Is it possible this token has been revoked? You might want to try generating a new one.

I tried with generating new token and then re ran the pipeline. Still it got failed

Perhaps the user is lacking Execute Analysis permissions on the project – have you verified?

for few repos its working , for few repos only its not working . If the issue is with user then it has to fail for all the pipelines right ?

Execute Analysis is a permission that can be granted per-project.

where can we check that one ?

Execute Analysis permission also enabled but still its fails with the same error.

Thanks.

Have you made sure that CI_PROJECT_ROOT_NAMESPACE is equal to your SonarCloud organization key?

/o:“${CI_PROJECT_ROOT_NAMESPACE}”

Yes , verified both are same

Hi Colin ,

any update on this.

Thanks.

No specific update to share.

My suggestion would be to make sure that you have this running correctly locally (without the complexity of all the environment variables), and once it’s successful make sure those environment variables are resolving as expected.