天天看点

Jenkins集合Sonar使用(windows)

Jenkins集合Sonar使用(本地)

1.http://localhost:8080/打开jenkins,新建Item

2.输入任务名,跟项目名保持一致,点击Freestyle project,点击确定

3.在http://localhost:8080/job/auth-server/configure页面配置,点击构建下面的增加构建步骤,选择Execute SonarQube Scanner,在下面的Analysis properties中添加:

# must be unique in a given SonarQube instance
sonar.projectKey=auth-server
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=auth-server
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=.
sonar.java.binaries=./target/classes
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
           

4.把项目复制到:C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace下面

5.点击应用和保存

6.在http://localhost:8080/job/auth-server/点击Build Now

windows启动sonarqube(本地)

1.本地路径

D:\sonarqube-8.3.1.34397\bin\windows-x86-64
           

2.双击启动StartSonar.bat

3.修改sonarqube默认配置

D:\sonarqube-8.3.1.34397\conf
           

修改sonar.properties,添加

sonar.sorceEncoding=UTF-8
sonar.login=admin #web页面注册的账号
sonar.password=admin #web页面注册的密码
           

修改wrapper.conf,使得sonarqube默认调用jdk13

# Path to JVM executable. By default it must be available in PATH.
# Can be an absolute path, for example:
#wrapper.java.command=/path/to/my/jdk/bin/java
#wrapper.java.command=java
wrapper.java.command=C:\Program Files\Java\jdk-13.0.2\bin\java

#
# DO NOT EDIT THE FOLLOWING SECTIONS
#
           

4.在需要进行代码检查的项目下新建sonar-project.properties

--projectName

----src

----target

----projectName.iml

----pom.xml

----sonar-project.properties
           

5.在sonar-project.properties中添加

# must be unique in a given SonarQube instance
sonar.projectKey=projectName
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=projectName
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=.
sonar.java.binaries=./target/classes
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
           

6.在该项目路径下cmd,启动sonar-scanner.bat

路径:

E:\Project\版本\sac_v34.2\base-service-platform\projectName
           

启动sonar-scanner

sonar-scanner
           

在Linux启动sonar

#cd 到脚本目录下
cd /usr/local/sonarqube/sonarqube-8.3.1.34397/bin/linux-x86-64
#启动脚本命令
./sonar.sh
           

继续阅读