代码质量检查sonarqube部署

1,669 阅读1分钟

软件版本:

sonarqube 8.0:
https://www.sonarqube.org/downloads/
postgresql 10.x:
https://www.postgresql.org/download/
SonarScanner 4.2:
https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/

依赖版本

汉化补丁sonar-l10n-zh-plugin-8.0.jar: 
https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-8.0/sonar-l10n-zh-plugin-8.0.jar
jdbc postgresql-42.2.9.jar:
https://jdbc.postgresql.org/download/postgresql-42.2.9.jar

从zip压缩包安装

首先去sonarqube官网下载zip包

下载zip包
把下载好的文件解压到 /[path]/sonarqube/

打开 SonarQube Server,使用内置数据库启动

直接用启动命令(点击跳转)启动

用系统管理员账号 (login=admin, password=admin),登录 http://localhost:9000

打开 SonarQube Server,使用外置数据库启动

首先修改sonarqube/conf/sonar.properties

 sonar.jdbc.username=sonarqube
 sonar.jdbc.password=aqwsed
 sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube

第二步,安装jdbc

下载jdbc的jar: https://jdbc.postgresql.org/download.html#current

创建文件夹`sonarqube/extensions/jdbc-driver/postgresql/`

把下载的jar,copy到创建的文件夹下

安装和配置psotgresql数据库

下载postgresql:https://www.postgresql.org/

安装postgresql,参考https://www.runoob.com/postgresql/linux-install-postgresql.html,注意端口要是5432

创建用户`CREATE USER sonarqube WITH PASSWORD 'aqwsed';`

基于sonarqube角色创建名为sonarqube 的数据库:
`CREATE DATABASE sonarqube
    WITH 
    OWNER = sonarqube
    ENCODING = 'UTF8'
    LC_COLLATE = 'C'
    LC_CTYPE = 'C'
    TABLESPACE = pg_default
    CONNECTION LIMIT = -1;`

启动命令

带log启动

/[path]/sonarqube/bin/[OS]/sonar.sh console

作为服务启动

/[path]/sonarqube/bin/[OS]/sonar.sh start

安装中文

汉化jar包, 放到sonarqube/extensions/plugins/下面,重启服务

安装代码扫描工具

安装

官方下载链接:docs.sonarqube.org/latest/anal…

Expand the downloaded file into the directory of your choice. We'll refer to it as $install_directory in the next steps.

Update the global settings to point to your SonarQube server by editing $install_directory/conf/sonar-scanner.properties:

#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
Add the $install_directory/bin directory to your path.

启动扫描

web项目根目录下执行

sonar-scanner

web配置

配置sonar-project.properties

sonar.projectKey=fe_task_pkg
sonar.sources=src
sonar.exclusions=src/**/*.test.js,src/**/*.test.jsx
sonar.javascript.file.suffixes=js,jsx
sonar.typescript.lcov.reportPaths=tests/coverage/lcov.info

将jest coverage报告转换sonar可读,看这里

其他

docker下载


参考文章:

菜鸟教程 - postgresql