Usage of property : TreatWarningsAsErrors=true

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension) : * Enterprise Edition Version 7.9.1 (build 27448), Scanner 4.0.0.1744

  • what are you trying to achieve : How to use/set-up this property : TreatWarningsAsErrors=true

  • what have you tried so far to achieve this

Hi @titukp12,

To help me answer your question, can you give me a bit more information about the languages and tools you’re working with? I’m guessing from your question that you’re building a C# or .NET project under MSBuild, is that right?

Regards,

Cameron.

Hi Cameron,

Its Salesforce project, with Apex and Xml languages more in use

Hi @titukp12,

So you’re probably using the plain SonarScanner, is that right? The reason I ask is that TreatWarningsAsErrors isn’t a SonarQube flag. AFAIK, it’s only an MSBuild flag, so it’s not applicable at all in this situation. Can you give me any more information about what you’re trying to achieve here?

Regards,

Cameron.

Yes, We are using plain SonarScanner and on Sonar server

What we are trying to achieve by this is that with below warning while scan should not upload the analysis report to sonar server, Currently it is uploading the report to central sonar server with this warnings.

Why we don’t want to upload the scan report to server with this warning is because we have implemented on all our projects base line concept where old issues to made false positive/won’t fix and QG passed one time exception to all old issues so that only new code issues are detected as failure and fix needed by dev team.
if there are malformed files that we cannot analyse then the job should fail and we should not upload a report to SonarQube

Since below warning of unable to analyse file which is already base lined, what it does is it will reintroduce the same file next time scan as new file and all old issues which base lined before reappear as new issues again. This is difficult tasks to identify which job and when it happened bcoz there are lot of multiple jobs/teams running on same project and sometimes we lose job history , Also we need to give exception approval again for same issues and baseline it again.

So we are trying fail at first stage before upload the scan report to server so that dev team will know about this warning job failures so that we can take better measures.

17:05:20 WARN: Unable to analyse file [file:///var/lib/jenkins/workspace/Accenture_SEAA/Accenture_SEAA_ID/TPM-SF-PullRequest-ID-CI/src/permissionsets/TPM_SystemAdmin.permissionset;](file://var/lib/jenkins/workspace/Accenture_SEAA/Accenture_SEAA_ID/TPM-SF-PullRequest-ID-CI/src/permissionsets/TPM_SystemAdmin.permissionset;)

HI @titukp12,

Firstly, I’m happy to see your dev teams are baselining their code and using Clean as you Code :slight_smile:

I can understand why you would want to abort the scan for malformed files, although there’s an assumption underlying the scanner, which is that your teams are writing syntactically correct code. The scanner also does its very best to complete a scan if any errors are recoverable and I doubt very much that we will change this behaviour, but it’s food for thought on our side.

In any case a change isn’t likely in the immediate future, so you may want to consider monitoring stderr (which is where all our warnings are written) and killing the scanner process if the scanner writes to it.

Regards,

Cameron.

Hi @titukp12,

Can you give me any more information on why the analyzer was unable to scan your code? I’m assuming syntax errors, but I’d like to understand in more detail. Is this a recurring problem, or a once-off? Would it be possible to provide the scanner logs?

Regards,

Cameron.