到现在为止,已经将sonarQube服务器搭建好,服务器是Linux服务器,基于sonarQube6.1配置的

原理关于sonarQube的工作原理,暂时还不是太清楚,据同事的分析,是在本机调用服务器对本地的原代码进行扫描,扫描完成之后,将结果保存至服务器,开发同事再登陆至服务器,查看报告并处理问题等

使用MSBuild扫描

针对是源码已经存在本地的同事

参考官方文档:http://docs.sonarqube.org/display/SCAN/From+the+Command+Line

下载:http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild

(1)下载并解压SonarQube Scanner for MSBuild

https://github.com/SonarSource-VisualStudio/sonar-scanner-msbuild/releases/download/2.2/sonar-scanner-msbuild-2.2.0.24.zip 下载至本地,并解压至一个路径,例如"D:\ms\"中

(2)修改SonarQube.Analysis.xml文件

要修改的地方只是关于sonarQube服务器的一些配置,关于服务器URL、USER、PASSWORD等

注意,这里的参数User/PassWord是登陆sonarQube平台的用户名和密码,请不要与sonarQube的DB登陆用户名和密码搞混淆。

<?xml version="1.0" encoding="utf-8" ?>
<!--
This file defines properties which would be understood by the SonarQube Scanner for MSBuild, if not overridden (see below)
By default the MSBuild.SonarQube.Scanner.exe picks-up a file named SonarQube.Analysis.xml in the folder it
is located (if it exists). It is possible to use another properties file by using the /s:filePath.xml flag The overriding strategy of property values is the following:
- A project-specific property defined in the MSBuild *.*proj file (corresponding to a SonarQube module) can override:
- A property defined in the command line (/d:propertyName=value) has which can override:
- A property defined in the SonarQube.Analysis.xml configuration file [this file] which can override:
- A property defined in the SonarQube User Interface at project level which can override:
- A property defined in the SonarQube User Interface at global level which can't override anything. Note that the following properties cannot be set through an MSBuild project file or an SonarQube.Analysis.xml file:
sonar.projectName, sonar.projectKey, sonar.projectVersion
The following flags need to be used to set their value: /n:[SonarQube Project Name] /k:[SonarQube Project Key] /v:[SonarQube Project Version] -->
<SonarQubeAnalysisProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1"> <Property Name="sonar.host.url">sonarQubeServerURL</Property> <Property Name="sonar.login">admin</Property>
<Property Name="sonar.password">password</Property>
<!-- Required only for versions of SonarQube prior to 5.2 -->
<!--
<Property Name="sonar.jdbc.url">jdbc:jtds:sqlserver://mySqlServer/sonar;instance=SQLEXPRESS;SelectMethod=Cursor</Property>
<Property Name="sonar.jdbc.username">sonar</Property>
<Property Name="sonar.jdbc.password">sonar</Property>
--> </SonarQubeAnalysisProperties>

(3)打开源代码文件夹,例如”F:\test\ArasCheckItem\ArasCheckItem“,在当前的路径打开cmd(按住Shift键并鼠标右键),或者打开cmd窗口,并通过命令进入至该源码目录

(3.1)运行命令MSBuild.SonarQube.Runner.exe,本文示例运行命令时加入路径是因为我没有将MSBuild的路径加入至环境变量,如加入了环境变量,可以直接运行MSBuild.SonarQube.Runner.exe,请注意,参数请使用双引号

参数说明:

/key(简写k):对应projectKey即项目的唯一代码,如两套源代码使用同一个projectKey那扫描的结果将混在一起,所以一个项目需要有一个单独的projectKey

/name(简写n):对应projectName即项目的名称,为项目的一个显示的名称,建立使用完整的项目名称

/version(简写v):对应projectVersion即项目的版本,项目在不同的时期版本也是不一样的,如果方便,可以在sonarQube的服务器中查看到不同的版本代码其中问题的变化

以下为完整参数与简写参数命令

"d:\ms\MSBuild.SonarQube.Runner.exe" begin /k:"testproject" /n:"mytestproject" /v:"1.9"
"d:\ms\MSBuild.SonarQube.Runner.exe" begin /key:"testproject" /name:"mytestproject" /version:"1.9"

(3.2)运行命令MSBuild.exe,这个MSBuild是系统安装过VS后会存在的一个编译器,以Visual Studio 2013为例,地址是:C:\Program Files (x86)\MSBuild\12.0\Bin

"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" /t:Rebuild (这里的参数/t如果不指定也是可以扫描出来的,看下图)

(3.3)运行命令MSBuild.SonarQube.Runner.exe,告诉sonarQube运行完成了,将报告上传

"d:\ms\MSBuild.SonarQube.Runner.exe" end

最新文章

  1. Windows Phone App Studio发布重要更新-支持Windows 8.1 源代码生成
  2. Angularjs 脏值检测
  3. 北京动软VAR团队的HoloLens开发教程最新搜罗整理
  4. C#----GDI+画图的一些注意和细节
  5. (一)MII/MDIO接口详解
  6. CF---(452)A. Eevee
  7. JIRA安装过程中链接mysql的问题!
  8. Android中如何查看内存(上)
  9. 生成四位随机数的PHP代码
  10. C++刷称号——2707: 素数与要素
  11. POJ1291-并查集/dfs
  12. 通过jersey-client客户端调用Jersey的Web服务模拟CURD
  13. MySQL中的字符串函数
  14. 字符串的一些常用方法 string
  15. 【面试笔试算法】Program 6: 字符消除(hiho题库)
  16. 自动备份远程mongodb数据库并拉取到本地
  17. ./sample_mnist: error while loading shared libraries: libnvinfer.so.4: cannot open shared object file: No such file or directory
  18. Win10系统的SurfacePro4如何重装系统-3 重装完成之后的系统优化
  19. c++ primer 笔记 (二)
  20. mysql帮助命令

热门文章

  1. win下删除oracle
  2. 第一篇 关于Android Studio的快捷键
  3. ZooKeeper分层次的法定人数(十二)
  4. LightOJ 1269 - Consecutive Sum Trie树
  5. 【C++ STL】Map和Multimap
  6. Vuejs - 组件式开发
  7. 6.0docker Dockerfile文件
  8. 第一章: 文件句柄转化为 typeglob/glob 与文件句柄检测
  9. 【Matlab】让Matlab程序发出声音
  10. Linux 入门记录:十一、Linux 用户基础