Error Running sonar.cfamily analysis in VSTS

I’m trying to execute a simple scan over a Linux Debian/perl based code (without having to do a full build) -getting error:

018-07-02T08:32:48.7072732Z INFO: Using 1 thread for analysis according to value of “sonar.cfamily.threads” property.
2018-07-02T08:32:48.7274550Z ##[error]ERROR: Property “sonar.cfamily.build-wrapper-output” was not specified.

which stops execution. VSTS is cloud hosted and using Sonar cloud to undertake analysis.

Hi Nick,

This error means that SonarCloud found C/C++ files which require first a full build (with the C/C++ build wrapper) to make sure the correct configuration is passed through the build wrapper output file. So in other words: it’s not possible to run an analysis on C/C++ without having first built the source code.

Running into the same problem and can’t find any documentation on how to get this resolved. Documentation only mentions to build it using the wrapper however nowhere does it state how to actually accomplish this using VSTS. Any assistance with this would be much appreciated.

You need to download the build wrapper and extract it somehow, before it is executed. A typical script would be something like:

curl -LsS https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip > build-wrapper-linux-x86.zip
unzip build-wrapper-linux-x86.zip
./build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output make clean all

And the you can trigger the analysis.

The problem is not running this locally as that’s easy. As I mention before, how do we do it from Visual Studio team Services (VSTS)??

Still not able to get this working natively in VSTS. Would be great if someone from SonarCloud could step up and provide some assistance here, I am sure there are many people that would benefit from knowing how to do this using VSTS and the Hosted build agents…

Ruan: the script I shared downloads the build wrapper, so you just need to add a Bash task (or similar - like a Powershell task if you prefer) in your Azure Pipeline and execute it before you trigger the “Run Analysis” task.

I’ve created VSTS-178 to make it easier for C/C++ users to configure their jobs.

Fabrice: Thanks for the feature request. I finally got it to build using the wrapper on a Hosted Windows machine in VSTS. All the tasks now succeeds however when I check sonarcloud after (the published link provided) it seems that there is no data. As in lot of the code is missing from the report. I’ve checked exclusions and only have the below, which is the same for other projects we have and works (although no wrapper needed for them). Any suggestions?

/NCalc//.
/Tests//.
**/NCalc/*.cs

Can you clarify:

  • if you are you trying to analyze a .NET solution that contains C# code
  • What exact command/tasks you are triggering to perform the analysis

Fabrice

Yes, the code is a combination of C# and C++.
The exact command is running below as cmd:

$(build.artifactstagingdirectory)/build-wrapper-3.11/win-x86-64/build-wrapper-win-x86-64.exe --out-dir $(build.artifactstagingdirectory)/bw-output C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"

I’m definitely not an expert in this C# and C++ mixed solutions, but it looks like you are missing some steps required to perform a successful analysis in this context.

Can you take a look at this “Building on Windows with MSBuild a Solution made of a mix of C++ and C#” doc page and tell if it helps?

Again that is if you build natively in windows if I am not mistaken? I’m using the steps provided in your help section for VSTS:

https://docs.sonarqube.org/pages/viewpage.action?pageId=6961393

Sure the Begin/and end tasks already does what you are proposing? I’ve attached the entire pipeline tasks.
pipeline

Hi Ruan,

do you think you could share logs from the build? (maybe even privately) Because without logs, this is going to be extremely difficult for me to be able to help you (running analyses on a solution which contains a mix of C#/C/C++ is probably the most complex use case we can think of).

Happy to work with you in whichever way we can get this resolved, as we are likely to have more project like this soon.

Hi @ruankr,

could you please provide the logs of two steps:

  • Build Solution Using Sonar Wrapper
  • Run Code Analysis

Hi Massimo

Sure, how can I share these with you privately?

Hi @ruankr,

sent you a PM.

Hi @ruankr,

from the logs I can see 25 c++ files analyzed and C# reports being imported. What do you mean when you say that you don’t see a lot of code? Are you referring to what files? C++? C#? Others?