Parse error not failing scan

On running the SonarCloud pipe in Bitbucket Pipelines, it does detect a syntax error in my code, but the run still finishes and Bitbucket pipelines considers the task to be a success

ERROR: Unable to parse file: app/example.py
ERROR: Parse error at line 17 column 26:
---------
INFO: Sensor Python Sensor [python] (done) | time=17632ms

I would have imagined this failing the build, but it does not. Is there something missing in my setup?

my bitbucket-pipelines.yml file has this block

  steps:
  - step: &sonarcloud
      name: Analyze on SonarCloud
      caches:
        - sonar
      script:
        - pipe: sonarsource/sonarcloud-scan:1.2.0

Welcome to the community!

Just to be clear, we separate the concepts of “build” and “code analysis”. Therefore, code analysis results are not meant to break the build. A build pipeline may have a final verification step to decide that based on the findings of code analysis, the pipeline should be considered failed, and block deployment.

Parse errors during the analysis do not cause the scanner process to fail. The scanner process collects all the findings from all the analyzers, submits as a report to SonarCloud, where your quality profile and quality gate configurations decide whether the code quality is considered good enough or not (quality gate passed or failed).

We have a rule to raise Python parsing errors as an issue (python:ParsingError). This rule is not activated in the default quality profile of SonarCloud (called Sonar Way). If you would like to activate this for your project, you can customize your quality profile accordingly. See the relevant documentation.

2 Likes

Facing the same issue. I added the python:ParsinError to the enabled rules. Now I have 2 errors in the azure pipeline output but the pipeline doesnt fail.
Any suggestion how I can make my pipeline fail?