k0p*_*kus 0 php sonar-runner sonarqube
我想评估SonarQube作为源代码检查工具.
该项目托管在一个git存储库中,我希望SonarQube在每次提交时检查我的PHP项目.
我通过docker获得了SonarQube的基本实例.(当前版本的声纳立方体是6.7 - 但我不知道步骤是否保持不变.这个答案考虑到了5.1.)
运行容器:
sudo docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube:5.1
Run Code Online (Sandbox Code Playgroud)
这提供了可访问的SonarQube的标准安装
http://localhost:9000/
Run Code Online (Sandbox Code Playgroud)
我可以通过用户名和passoword登录admin
,并通过以下方式安装PHP组件:
设置>系统>更新中心
(或:http://localhost:9000/updatecenter
)
并搜索PHP并安装.
在那里,我可以添加PHP和SonarQube服务器重新启动后,(通过我做的docker stop container_id
,container start container_id
),扩展被加载.
服务器不会运行您的测试.它只会显示结果.
您将需要一台专用于工作的机器sonar-runner
,为了快速入门,您可以使用本地开发机器和当地的bitbucket结账.在该机器上安装声纳转轮.
通过以下方式下载声纳转轮:
$ wget http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
Run Code Online (Sandbox Code Playgroud)
并将其提取到:
~/programs/sonar-runner-2.4
Run Code Online (Sandbox Code Playgroud)
在这个目录中,你找到一个conf/sonar-runner.properties
应该包含的文件:
#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here
#----- Default SonarQube server
sonar.host.url=http://localhost:9000
#----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#----- MySQL
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
#----- Security (when 'sonar.forceAuthentication' is set to 'true')
sonar.login=admin
sonar.password=admin
Run Code Online (Sandbox Code Playgroud)
进入项目的根目录并创建一个名为的文件sonar-project.properties
:
# must be unique in a given SonarQube instance
sonar.projectKey=yourProjectKey
# this is the name displayed in the SonarQube UI
sonar.projectName=yourProject
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=./classes/,./tests/
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
Run Code Online (Sandbox Code Playgroud)
然后我跑了:
your/projects/dir$: ~/programs/sonar-runner-2.4/bin/sonar-runner
Run Code Online (Sandbox Code Playgroud)
然后,您将在SonarCube仪表板上看到一个新条目.
归档时间: |
|
查看次数: |
8178 次 |
最近记录: |