到现在为止,已经将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登陆用户名和密码搞混淆。

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!--
  3. This file defines properties which would be understood by the SonarQube Scanner for MSBuild, if not overridden (see below)
  4. By default the MSBuild.SonarQube.Scanner.exe picks-up a file named SonarQube.Analysis.xml in the folder it
  5. is located (if it exists). It is possible to use another properties file by using the /s:filePath.xml flag
  6.  
  7. The overriding strategy of property values is the following:
  8. - A project-specific property defined in the MSBuild *.*proj file (corresponding to a SonarQube module) can override:
  9. - A property defined in the command line (/d:propertyName=value) has which can override:
  10. - A property defined in the SonarQube.Analysis.xml configuration file [this file] which can override:
  11. - A property defined in the SonarQube User Interface at project level which can override:
  12. - A property defined in the SonarQube User Interface at global level which can't override anything.
  13.  
  14. Note that the following properties cannot be set through an MSBuild project file or an SonarQube.Analysis.xml file:
  15. sonar.projectName, sonar.projectKey, sonar.projectVersion
  16. The following flags need to be used to set their value: /n:[SonarQube Project Name] /k:[SonarQube Project Key] /v:[SonarQube Project Version]
  17.  
  18. -->
  19. <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">
  20.  
  21. <Property Name="sonar.host.url">sonarQubeServerURL</Property>
  22.  
  23. <Property Name="sonar.login">admin</Property>
  24. <Property Name="sonar.password">password</Property>
  25. <!-- Required only for versions of SonarQube prior to 5.2 -->
  26. <!--
  27. <Property Name="sonar.jdbc.url">jdbc:jtds:sqlserver://mySqlServer/sonar;instance=SQLEXPRESS;SelectMethod=Cursor</Property>
  28. <Property Name="sonar.jdbc.username">sonar</Property>
  29. <Property Name="sonar.jdbc.password">sonar</Property>
  30. -->
  31.  
  32. </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的服务器中查看到不同的版本代码其中问题的变化

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

  1. "d:\ms\MSBuild.SonarQube.Runner.exe" begin /k:"testproject" /n:"mytestproject" /v:"1.9"
  1. "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

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

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

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

sonarQube Scanner的更多相关文章

  1. sonarqube+Scanner代码质量管理工具

    本文相关描述基于sonarqube 6.2版本. 下载地址: sonarqube下载网址:https://www.sonarqube.org/downloads/ Scanner下载网址(用于扫描项目 ...

  2. SonarQube Scanner的配置与使用简介

    一.下载 下载地址: https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.0.3.77 ...

  3. Jenkins 集成 SonarQube Scanner

    1.   安装Jenkins 下载安装包,这里我们下载war包 https://jenkins.io/download/ 运行jenkins.war的方式有两种: 第一种:将其放到tomcat中运行( ...

  4. 持续代码质量管理-SonarQube Scanner部署

    1. SonarQube Scanner地址 上一篇文章我们安装了SonarQube-7.3,让我们可以在页面查看代码质量.但是具体的扫描工作则需要SonarQube Scanner完成. 下载页面 ...

  5. Analyzing .net core application with SonarQube Scanner for MSBuild

    SonarQube是管理代码质量一个开放平台,省略安装过程,下面介绍下如何使用sonarqube去扫描c# 代码. 前提:下载SonarQube Scanner for MSBuild.https:/ ...

  6. CentOS6.8配置SonarQube Scanner配合SonarQube使用

    下载最新的SonarQube Scanner压缩包  https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner ...

  7. SonarQube Scanner for MSBuild

    到现在为止,已经将sonarQube服务器搭建好,服务器是Linux服务器,基于sonarQube6.1配置的 原理关于sonarQube的工作原理,暂时还不是太清楚,据同事的分析,是在本机调用服务器 ...

  8. 使用SonarQube和SonarQube Scanner分析项目

    一.概述 SonarQube的安装,请参考链接:https://www.cnblogs.com/xiao987334176/p/12011623.html 配置好sonar的服务端后,接下来就要使用s ...

  9. SonarQube Scanner execution execution Error --- Failed to upload report - 500: An error has occurred. Please contact your administrator

    问题原因:mysql参数设置问题 检查mysql参数: mysql> SHOW VARIABLES LIKE 'max_allowed_packet'; 修改/etc/my.cnf文件: [my ...

随机推荐

  1. 完全背包的变形POJ1252

    话说今天做背包做到有点累了,题目是英文的--而且还很长,我看了好久(弱爆了). 题目大概的意思就是,有六种硬币,之后,求用这六种硬币最小数目支付1到100美分的平均值,以及最小数目中的最大值. 很容易 ...

  2. boost::xml——基本操作以及中文乱码解决方案 (续)

    本博文主要想说明以下两点: 1.对于上一篇的<boost::xml——基本操作以及中文乱码解决方案>解释,这篇博文基本解决了正确输入输出中英文问题,但是好像还没有解决修改中文出现乱码的问题 ...

  3. 如何禁用easyui-linkbutton 中的Click事件

    eg: <a id="btn" href="#" class="easyui-linkbutton" data-options=&qu ...

  4. Jquery Mobile下设置radio控件选中

    问题: .html文件头部引入了: <script src="js/jquery.js"></script> <script src="js ...

  5. php基础知识【函数】(1)数组array

    一.排序 1.sort -- 从最低到最高排序,删除原有的键名,赋予新的键名[字母比数字高] 2.rsort -- 逆向排序(最高到最低),删除原有的键名,赋予新的键名[字母比数字高] 3.asort ...

  6. 精通 Oracle+Python,第 2 部分:处理时间和日期

    从 Python 2.4 版开始,cx_Oracle 自身可以处理 DATE 和 TIMESTAMP 数据类型,将这些列的值映射到 Python 的 datetime 模块的 datetime 对象中 ...

  7. 在oj平台上练习的一些总结【转】

    程序书写过程中的一些小技巧:1. freopen(“1.txt”,”r”,stdin); //程序运行后系统自动输入此文档里面的内容(不需要进行手动输入)freopen(“1.txt”,”w”,std ...

  8. ubuntu修改主机名称

    一.为何要修改主机名称 在安装Ubuntu时,一不小心主机名称输入的“too long”了,导致命令行上就提示符占据了一行的1/3,迫使我产生修改主机名称的冲动. 二.操作方法 原理:系统启动时,会从 ...

  9. 机务UI设计小节

    1.CSS样式 .header { background-color:#7A8692; color:White; height:30px; font-size:16px; width:100%; li ...

  10. Java基础——异常机制

    [捕获异常] 硬件的错误.输入错误.物理限制等问题,都可能导致程序运行时的异常出现. 1.异常的分类层次 在java中,异常对象都是由Throwable类继承而来的,主要分为两大类: Error和Ex ...