ciricihq / gitlab-sonar-scanner

This project is no longer maintained
GNU General Public License v3.0
80 stars 62 forks source link

Add documentation about sonar-project.properties file #14

Closed gudge25 closed 6 years ago

gudge25 commented 6 years ago
Running with gitlab-runner 10.1.0 (c1ecf97f)
  on docker-auto-scale (4e4528ca)
Using Docker executor with image ciricihq/gitlab-sonar-scanner ...
Using docker image sha256:c38adbd8d8ac40dbf41049bcec2b844d2ffadbb583ef7c076cc510355547140e for predefined container...
Pulling docker image ciricihq/gitlab-sonar-scanner ...
Using docker image ciricihq/gitlab-sonar-scanner ID=sha256:3013138cd504c8ec0fdccc94d2e952391445d9dde4ebe79b4d554aadcc878e54 for build container...
Running on runner-4e4528ca-project-4603510-concurrent-0 via runner-4e4528ca-srm-1510236136-77e6203a...
Cloning repository...
Cloning into '/builds/satskiy.a/KRUSHER'...
Checking out bc77635a as dev...
Skipping Git submodules setup
$ unset CI_BUILD_REF && /usr/bin/sonar-scanner-run.sh
INFO: Scanner configuration file: /sonar-scanner-3.0.3.778/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.0.3.778
INFO: Java 1.8.0_131 Oracle Corporation (64-bit)
INFO: Linux 4.11.12-coreos-r1 amd64
INFO: User cache: /root/.sonar/cache
INFO: Publish mode
INFO: Load global settings
INFO: Load global settings (done) | time=775ms
INFO: User cache: /root/.sonar/cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=209ms
INFO: Download sonar-flex-plugin-2.3.jar
INFO: Download sonar-scm-git-plugin-1.2.jar
INFO: Download sonar-gitlab-plugin-2.1.0.jar
INFO: Download sonar-scm-svn-plugin-1.5.0.715.jar
INFO: Download sonar-javascript-plugin-3.2.0.5506.jar
INFO: Download sonar-java-plugin-4.15.0.12310.jar
INFO: SonarQube server 6.6.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 11.350s
INFO: Final Memory: 45M/196M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.sources
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
ERROR: Job failed: exit code 1
elboletaire commented 6 years ago

You need a sonar-project.properties file, with the sonar.projectKey set, among others. Here's an example sonar-project.properties file:

# sonar project id
sonar.projectKey=YOUR_SONAR_PROJECT_KEY_ID
# main language to be analyzed
sonar.language=php
# included folders
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=config, plugins, src

# excluded folders
sonar.exclusions=plugins/**/tests/**, src/Console/Installer.php, plugins/**/config/**, config/Migrations/**

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
# Set gitlab analysis to exit instead of notifying via commit message
sonar.gitlab.failure_notification_mode=exit-code

You can see more information about this file in: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

Please, don't close the issue as we'll try to add a note about this file our readme file.

gudge25 commented 6 years ago

Thanks for reply i create sonar-project.properties file Picture (dev) http://imgur.com/UjHFgpXl.png

# sonar project id
sonar.projectKey=Krusher
# main language to be analyzed
sonar.language=JavaScript
# included folders
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=config, plugins, src

# excluded folders
sonar.exclusions=plugins/**/tests/**, src/Console/Installer.php, plugins/**/config/**, config/Migrations/**

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
# Set gitlab analysis to exit instead of notifying via commit message
sonar.gitlab.failure_notification_mode=exit-code

BUT STILL the same issue

Cloning repository...
Cloning into '/builds/satskiy.a/KRUSHER'...
Checking out 15883a03 as dev...
Skipping Git submodules setup
$ unset CI_BUILD_REF && /usr/bin/sonar-scanner-run.sh
INFO: Scanner configuration file: /sonar-scanner-3.0.3.778/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.0.3.778
INFO: Java 1.8.0_131 Oracle Corporation (64-bit)
INFO: Linux 4.11.12-coreos-r1 amd64
INFO: User cache: /root/.sonar/cache
INFO: Publish mode
INFO: Load global settings
INFO: Load global settings (done) | time=722ms
INFO: User cache: /root/.sonar/cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=176ms
INFO: Download sonar-flex-plugin-2.3.jar
INFO: Download sonar-scm-git-plugin-1.2.jar
INFO: Download sonar-gitlab-plugin-2.1.0.jar
INFO: Download sonar-l10n-ru-plugin-1.6.jar
INFO: Download sonar-scm-svn-plugin-1.5.0.715.jar
INFO: Download sonar-javascript-plugin-3.2.0.5506.jar
INFO: Download sonar-java-plugin-4.15.0.12310.jar
INFO: SonarQube server 6.6.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 8.319s
INFO: Final Memory: 45M/178M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.sources
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.

Maybe wrong place ? Thanks

elboletaire commented 6 years ago

Your runner is not taking the sonar-project.properties. Take a look to the line which says:

 INFO: Scanner configuration file: /sonar-scanner-3.0.3.778/conf/sonar-scanner.properties

Now take a look to the first comment you wrote. Both have exactly the same path, so, obviously, your runner is not taking the sonar-project.properties file.

Is that file added to the root of the project, commited, and pushed?

gudge25 commented 6 years ago

yes check a picture http://imgur.com/UjHFgpXl.png

elboletaire commented 6 years ago

Please, paste here how have you configured the runner in .gitlab-ci.yml (replace any sensible information with ** if required).

gudge25 commented 6 years ago
stages:
- analysis

sonarqube:
  stage: analysis
  image: ciricihq/gitlab-sonar-scanner
  variables:
    SONAR_URL: "https://www.krusher.duckdns.org"
    SONAR_PROJECT_VERSION: "$CI_BUILD_ID"
    SONAR_ANALYSIS_MODE: "issues"
  script:
  - /usr/bin/sonar-scanner-run.sh

sonarqube-reports:
  stage: analysis
  image: ciricihq/gitlab-sonar-scanner
  variables:
    SONAR_URL: "https://www.krusher.duckdns.org"
    SONAR_PROJECT_VERSION: "$CI_BUILD_ID"
    SONAR_ANALYSIS_MODE: "publish"
  script:
  - unset CI_BUILD_REF && /usr/bin/sonar-scanner-run.sh
gudge25 commented 6 years ago
# must be unique in a given SonarQube instance
sonar.projectKey=Krusher
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=Webfax
sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=.

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

working exammple!!!!

elboletaire commented 6 years ago

What do you mean with "working example"? Did you finally got it working?

elboletaire commented 6 years ago

Currently available under the develop docker tag.