.NET Scanner MSBuild 4.8: The 'organization' parameter is missing

Hello, we are using .NET SonarScanner for MSBuild version 4.8 and suddenly, we getting an error at the start of analysis:

dotnet sonarscanner begin /s:/app/shared/SonarQube.Analysis.xml /k:k2-shared /v:10.13.0"-k2-3247-e8ca944" /d:sonar.cs.vstest.reportsPaths="/app/shared/test/TestResults/*TestResults.trx" /d:sonar.cs.opencover.reportsPaths="/app/shared/test/TestResults/*TestCoverage.xml" /d:sonar.verbose=true /d:sonar.branch.name="feature/k2-3247" /d:sonar.branch.target="develop"
SonarScanner for MSBuild 4.8
Using the .NET Core version of the Scanner for MSBuild
Loading analysis properties from /app/shared/SonarQube.Analysis.xml
sonar.verbose=true was specified - setting the log verbosity to 'Debug'
Pre-processing started.
Preparing working directories...
Using environment variables to determine the download directory...
11:11:23.268  11:11:23.263  Loading analysis properties from /app/shared/SonarQube.Analysis.xml
11:11:23.268  11:11:23.268  sonar.verbose=true was specified - setting the log verbosity to 'Debug'
11:11:23.27  Updating build integration targets...
11:11:23.273  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/4.0/Microsoft.Common.targets/ImportBefore
11:11:23.274  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/10.0/Microsoft.Common.targets/ImportBefore
11:11:23.274  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/11.0/Microsoft.Common.targets/ImportBefore
11:11:23.275  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/12.0/Microsoft.Common.targets/ImportBefore
11:11:23.275  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/14.0/Microsoft.Common.targets/ImportBefore
11:11:23.275  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/15.0/Microsoft.Common.targets/ImportBefore
11:11:23.276  Installed SonarQube.Integration.ImportBefore.targets to /root/.local/share/Microsoft/MSBuild/Current/Microsoft.Common.targets/ImportBefore
11:11:23.276  Installed SonarQube.Integration.ImportBefore.targets to /root/Microsoft/MSBuild/15.0/Microsoft.Common.targets/ImportBefore
11:11:23.276  Installed SonarQube.Integration.ImportBefore.targets to /root/Microsoft/MSBuild/Current/Microsoft.Common.targets/ImportBefore
11:11:23.277  Installed SonarQube.Integration.targets to /app/shared/.sonarqube/bin/targets
11:11:23.278  Creating config and output folders...
11:11:23.278  Creating directory: /app/shared/.sonarqube/conf
11:11:23.278  Creating directory: /app/shared/.sonarqube/out
11:11:23.285  Fetching analysis configuration settings...
11:11:23.286  Downloading from https://sonarcloud.io/api/server/version...
11:11:23.583  Fetching properties for project 'k2-shared' from https://sonarcloud.io/api/settings/values?component=k2-shared...
11:11:23.584  Downloading from https://sonarcloud.io/api/settings/values?component=k2-shared...
11:11:23.843  Downloading from https://sonarcloud.io/api/languages/list...
11:11:23.89  Fetching quality profile for project 'k2-shared' from https://sonarcloud.io/api/qualityprofiles/search?projectKey=k2-shared...
11:11:23.89  Downloading from https://sonarcloud.io/api/qualityprofiles/search?projectKey=k2-shared...
11:11:23.945  Failed to request and parse 'https://sonarcloud.io/api/qualityprofiles/search?projectKey=k2-shared': The remote server returned an error: (400) .
Unhandled exception. System.Net.WebException: The remote server returned an error: (400) .
   at System.Net.HttpWebRequest.GetResponse()
   at System.Net.WebClient.GetWebResponse(WebRequest request)
   at System.Net.WebClient.DownloadBits(WebRequest request, Stream writeStream)
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadString(Uri address)
   at System.Net.WebClient.DownloadString(String address)
   at SonarScanner.MSBuild.PreProcessor.WebClientDownloader.<>c__DisplayClass5_0.<TryDownloadIfExists>b__0()
   at SonarScanner.MSBuild.PreProcessor.WebClientDownloader.DoIgnoringMissingUrls(Action op)
   at SonarScanner.MSBuild.PreProcessor.WebClientDownloader.TryDownloadIfExists(String url, String& contents)
   at SonarScanner.MSBuild.PreProcessor.SonarWebService.<>c__DisplayClass6_0.<TryGetQualityProfile>b__0()
   at SonarScanner.MSBuild.PreProcessor.SonarWebService.DoLogExceptions[T](Func`1 op, String url, Action`1 onError)
   at SonarScanner.MSBuild.PreProcessor.SonarWebService.TryGetQualityProfile(String projectKey, String projectBranch, String organization, String language, String& qualityProfileKey)
   at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.FetchArgumentsAndRulesets(ISonarQubeServer server, ProcessedArgs args, TeamBuildSettings settings, IDictionary`2& serverSettings, List`1& analyzersSettings)
   at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs localSettings)
   at SonarScanner.MSBuild.PreProcessor.TeamBuildPreProcessor.Execute(String[] 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, Boolean showDeprecatedWarning)
   at SonarScanner.MSBuild.Program.Main(String[] args)

If you click on the link in the error message, you get this error:
{"errors":[{"msg":"The 'organization' parameter is missing"}]}

This is how the SonarQube.Analysis.xml file looks like:

<?xml version="1.0" encoding="utf-8" ?>
<SonarQubeAnalysisProperties  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">

  <Property Name="sonar.host.url">https://sonarcloud.io</Property>
  <Property Name="sonar.organization">alza</Property>
  <Property Name="sonar.login">xxx</Property>
  <Property Name="sonar.sources">src/*,src-packages/*</Property>
  <Property Name="sonar.exclusions">src/**/wwwroot/*,src/**/Assets/Migrations/*</Property>
  
</SonarQubeAnalysisProperties>

As you can see, the organization is set properly in the XML file…

As a matter of fact, I don’t think we changed anything at all and suddely, this error occurs… Can you help please? Thank you

PS: The dotnet tool is installed as following:
dotnet tool install --global dotnet-sonarscanner --version 4.8.0

Hi,

Thanks for reporting. It seems related to a change we deployed today.
We’re currently looking into it and will keep you posted.

Benoit

Hi @zsojma and welcome to the community !

The error you get was indeed introduced by some changes made around organization management that were deployed this morning.

That being said, the sonar.organization, in the context of the Scanner for MSBuild, has a different way of working : as per the documentation this parameter should be passed in the commandLine directly, with /o:{your organization} (-o:{your organization} also works).

Please note however that this concerns only the retrieval of the quality profile (which, for some reasons, might have never work on your particular case), and not the analysis itself, which continue to work.

So, as a fix, please profile the organization with the needed flag, we’re are still looking on our side why the setting in the XML file was never parsed.

Thanks and sorry for the incovenience.

Mickaël

2 Likes

Hi,

I can confirm this works.

Thanks,
Damien

2 Likes

Hi, thanks for help. This also works for me.

Thanks,
Zdeněk

1 Like

@mickaelcaro

We are currently experiencing the same issue, but we cannot use a commandline approach, as this error is being raised by the prepare sonar task.

I raised the following ticket: Unable to run sonarscan because of error 400 by retrieving qualityprofile since a few days

1 Like

Hi @Edwin,

Please use the dedicated SonarCloud extension if you want to benefit from organization support, and target SonarCloud.

Mickaël

Hello @mickaelcaro, as I understood from the past, The SonarCloud extension is not compatible with the onpremise Devops. Or did this change?

This kind of scenario is not supported indeed.

SonarCloud is meant to be used with Azure DevOps Services (cloud version)
SonarQube with Azure DevOps Server / TFS (On-Prem)

Mickaël

Ok, so our only option is now to return to an onpremise setup instead of using the cloud? :disappointed:

This reply is marked as solution but I really dint get what is solution. I am getting the same error while running Preepare Analysis task from azure pipeline. Even tried giving the option parameter sonar.organization= but it is not pickng it.

Hi @varunverma

Which extension are you using ? SonarQube or SonarCloud ?

Hi Mickael,
I am using Sonarcloud. It worked for me when I use the maven project instead of the MSBuild option in Prepare analysis Phase.

The organization param for SonarCloud will be set once you’ve selected your organization in the dropdown.

This is an issue for us as well - we use Jenkins to pass in url and auth and use the sonarscanner msbuild command line from jenkinsfiles. We want to be able to fail back to on-prem if cloud is unavailable. However, that currently requires change to jenkinsfile or script. I just want to change the sonar config in jenkins and include organization for cloud there rather than include a copy of that in every jenkinsfile. :frowning: