SonarQube server does not report any errors (while the pipeline job sees errors)

I’ve installed SonarQube on Kubernetes with a pipeline running on Gitlab.

I’ve committed 2 PHP files to a test repository and introduced some syntax errors to them.
Unfortunately, SonarQube dashboard does not show any errors, even though the pipeline is catching them.
The pipeline job is detecting these errors:

INFO: Starting PHP rules
INFO: 2 source files to be analyzed
ERROR: Unable to parse file [file:///builds/sonar-test/testcode/php/test.php] at line 4
ERROR: Parse error at line 4 column 1:
1: <?php
2: 
3: phpinfo()
4: 
   ^
ERROR: Unable to parse file [file:///builds/sonar-test/testcode/php/test-broken.php] at line 4
ERROR: Parse error at line 4 column 1:
1: <?php
2: 
3: phpinfo()
4: 
   ^
INFO: 2/2 source files have been analyzed

The pipeline job ends as successful:

INFO: QUALITY GATE STATUS: PASSED - View details on https://my-url/dashboard?id=test-project
INFO: Analysis total time: 29.535 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 33.209s
INFO: Final Memory: 17M/55M
INFO: ------------------------------------------------------------------------
Saving cache for successful job
00:01
Creating cache sonarqube-check-non_protected...
.sonar/cache: found 55 matching files and directories 
Archive is up to date!                             
Created cache
Cleaning up project directory and file based variables
00:01
Job succeeded

However, when I go to SonarQube project / dashboard URL, it claims there are no errors.

Configuration:

$ cat .gitlab-ci.yml 
sonarqube-check:
  tags:
    - test
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner
  allow_failure: true
  only:
    - sonarqube-test # or the name of your main branch
testjob:
  tags:
    - test
  script:
    - whoami
$ cat sonar-project.properties 
sonar.projectKey=test-project
sonar.qualitygate.wait=true

Hi,

Welcome to the community!

Those errors aren’t necessarily problems in your code. They’re telling you SonarQube doesn’t understand the code and can’t examine it for issues.

If you want to see these parse errors in your analysis results, you’ll need to enable rule S2260, which reports parse errors forward into analysis. Note that if you’re using a Sonar way profile, you won’t be able to modify it to add the rule. You’ll need to make a copy, add the rule to the copy and (probably) set the copy as your default profile.

 
HTH,
Ann

2 Likes

Thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.