重要:一定要下載sonar qube7.9以下版本,其7.9以上版本不支持mysql,否則 白安裝了。
四、在jenkins中,使用 pipelilne與sonar qube結合使用
(1)pipeline 配置如下,‘xx’中的內容 分別對應sonar scanner和sonar qube 在jenkin配置中起的名
(2)sonar scanner和sonar qube 在jenkin配置中起的名 ,分別如下:
三、jenkins與sonarqube相結合,檢查代碼質量
(1)配置jenkins中的某個項目,參數爲如下:
# must be unique in a given SonarQube instance
sonar.projectKey=seleniumdemo
# this is the name displayed in the SonarQube UI
sonar.projectName=seleniumdemo
sonar.projectVersion=1.0
# 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=src
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
#path to your project build output path
sonar.java.binaries=target/classes
(2)配置完成後,構建項目
二、jenkins中安全sonar qube scanner 和sonar scanner
1、安裝sonar qube scanner插件
2、使用sonarQube Scanner安裝sonar Scanner
進入全局工具管理頁面
3、
3、配置安裝sonar scanner客戶端,全局工具配置
4、在jenkin中配置sonar qube服務的環境,進入系統配置
(1)先新增sonarqube的憑證
(2)配置sonarqube環境
一、下載並安裝sonar qube
- sonar qube官網下載zip包,解壓,我下載的是sonarqube-8.2
- 只能使用sonar qube用戶進入sonar 故創建sonar 用戶名
因我是MAC電腦,故點擊左上角的蘋果標識-系統配置-用戶和羣組,創建的用戶和羣組
- 使用剛創建的sonar來管理sonarqube目錄,即切換權限
- 修改sonar配置,修改sonarqube-8.2/conf/sonar.properties 文件,配置mysql的用戶名和密碼 及連接方式,sonar的默認端口9000也是在此文件中,
- 啓動sonar,注意 要使用sonar用戶啓動。切換到sonar用戶,啓動
MAC 切換用戶命令: su - 用戶名
su sonar /Users/yp-tc-m-2935/Downloads/tooljar/sonarqube-8.2/bin/macosx-universal-64/sonar.sh start
報錯:
--> Wrapper Started as Daemon
Launching a JVM...
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
WrapperSimpleApp: Encountered an error running main: org.sonar.process.MessageException: Unsupported JDBC driver provider: mysql
org.sonar.process.MessageException: Unsupported JDBC driver provider: mysql
<-- Wrapper Stopped
--> Wrapper Started as Daemon
Launching a JVM...
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
WrapperSimpleApp: Encountered an error running main: org.sonar.process.MessageException: Unsupported JDBC driver provider: mysql
org.sonar.process.MessageException: Unsupported JDBC driver provider: mysql
<-- Wrapper Stopped
經百度查詢:得知Sonar Qube7.9以上已不支持mysql,故刪除該版本,降級版本到7.8,重新配置
換7.8版本,執行上述步驟後,執行啓動,一定要使用sonar用戶啓動,否則會啓動失敗
查看日誌:logs/sonar.log
輸入:http://127.0.0.1:9000/ ,點擊login in進行登錄,sonar 默認用戶名和密碼均都是:admin
生成令牌,用於jenkins登錄sonarqube時使用。
複製:75326e43b802c79d0f42ed8bbba445dfc82dd579