cathive / concourse-sonarqube-resource

performs SonarQube analyses and checks quality gates https://concourse-ci.org/ https://sonarqube.org/
Apache License 2.0
46 stars 50 forks source link

Analysis job fails right after reading scanner report #24

Closed jakub-zieba closed 5 years ago

jakub-zieba commented 5 years ago

Hello, I am building POC locally. I have concourse, sonar and postgres running locally in docker containers and one js project I run scans on. Everything appears to be working perfectly, scan report is visible in my sonar web UI. There is also present some second output for the put step, which is very unclear to me. What interested me is the part of the output saying: Reading SonarQube scanner report (./.scannerwork/report-task.txt)... Which is not part of usual sonar-scanner command output. Build configuration is trivial:

- name: sonar-runner
  type: docker-image
  source:
    repository: cathive/concourse-sonarqube-resource
    tag: latest

resources:
- name: src
  type: git
  source:
    uri: omitted
    branch: develop
    private_key: ((private_key))

- name: code-analysis
  type: sonar-runner
  source:
    host_url: omitted
    login: ((sonar_token))
jobs:
- name: analysis
  plan:
  - get: src
    trigger: false
  - put: code-analysis
    params:
      project_path: src
      additional_properties:
        sonar.projectKey: frontend-dev
        sonar.sources: .

screen shot 2018-09-18 at 14 40 03

thejaswis commented 5 years ago

Hi

I am also facing same issue. Please provide solution.

headcr4sh commented 5 years ago

.scannerwork/report-task.txt is a file that is being created by the sonar-runner. Even though it has a .txt suffix, it is indeed a regular ISO-8859-1 (Latin1) encoded .properties file as it is commonly used in many places throughout the Java ecosystem.

Not quite sure, what's your problem here...

.scannerwork/report-task.txt is used by the sonarqube-resource to figure out the ID of the analysis task that is being spawned by SonarQube (this is an asynchronous process!) and this task ID is used to query/poll SonarQube while we wait that the task is being finished.

For further details about the file see: https://stackoverflow.com/questions/40337014/why-doesnt-my-sonar-scanner-run-create-a-report-task-txt-file

jakub-zieba commented 5 years ago

The issue is not the file but lack of knowledge what is being launched right after it is being created. It is not decribed anywhere so I do not know what flag or modification I should apply. And this is not default behaviour of adequate command lunched in terminal.

cah-masonmcallaster commented 5 years ago

Doing a little bit of digging, it appears to me that the problem lies with the read_properties command (line 185 of out)

Upon hijacking the task, that command is not found (though I assume it's mean to be the readproperties.awk file). I don't see that file being pushed into the user path by that name inside of the Dockerfile

However, that would imply that this is a problem for anyone using the latest version of this resource.

edit: Looks like that function should be available inside of common.sh - the source of the out file (not sure how I missed that). But the script does seem to be failing at around the point it is used.

headcr4sh commented 5 years ago

Can you please try to set the __debug flag as documented in the README file? This should give some more detailed outputs and provide some insights about what's going on....

opicaud commented 5 years ago

I have same issue. See the logs

INFO] 17:40:29.119 More about the report processing ... [DEBUG] 17:40:29.121 Report metadata written to /tmp/build/put/build-output/target/sonar/report-task.txt [DEBUG] 17:40:29.144 Post-jobs : [INFO] 17:40:29.176 Task total time: 35.731 s [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 03:50 min [INFO] Finished at: 2018-12-08T17:40:29Z [INFO] ------------------------------------------------------------------------ + echo 'Reading SonarQube scanner report (./.scannerwork/report-task.txt)...' Reading SonarQube scanner report (./.scannerwork/report-task.txt)...

The report is not fetched in the right directory.

headcr4sh commented 5 years ago

Found the problem. The resource makes some false assumptions about the location of report-task.txt if the scanner_type has been manually set to maven. (scanner_type=auto) should work as supposed to.

I am preparing a fix. Version 0.7.1 will contain an updated "out" script that incorporates a fix for locating the report-task.txt file.

nickyhannaway-coats commented 5 years ago

This is still failing in version 0.9.1 for me. Furthermore, I have the scanner_type set to auto. Weirdly when the sonar quality gate passes I see the same issue yet when it fails the report seems to be received and parsed just fine.

opicaud commented 5 years ago

This is still failing in version 0.9.1 for me. Weirdly when the sonar quality gate passes I see the same issue yet when it fails the report seems to be received and parsed just fine.

I use 0.8.1