到现在为止,已经将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

SonarQube Scanner for MSBuild的更多相关文章

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

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

  2. (持续集成)win7上部署Jenkins+MSBuild+Svn+SonarQube+SonarQube Scanner for MSBuild (第二发)

    这一篇进入实战,走起.... 登录jenkins,如下图 点击上图中的“新建”按钮,进入下图 输入项目名称,选择“构建一个自由风格的软件项目”即可,点击“ok”,跳转到下图 svn源代码管理(选择代码 ...

  3. (持续集成)win7上部署Jenkins+MSBuild+Svn+SonarQube+SonarQube Scanner for MSBuild (一)

    一.Jenkins介绍 jenkins是一个广泛用于持续构建的可视化web工具,持续构建说得更直白点,就是各种项目的”自动化”编译.打包.分发部署.jenkins可以很好的支持各种语言(比如:java ...

  4. sonarQube Scanner

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

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

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

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

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

  7. Jenkins 集成 SonarQube Scanner

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

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

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

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

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

随机推荐

  1. 使用VS2010编译MongoDB C++驱动详解

    最近为了解决IM消息记录的高速度写入.多文档类型支持的需求,决定使用MongoDB来解决. 考虑到MongoDB对VS版本要求较高,与我现有的VS版本不兼容,在leveldb.ssdb.redis.h ...

  2. Redrain 通用菜单控件使用方法和说明(附源码和demo)

    转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/42889709 大概半年前我写过博客说明怎么改造duilib的原代Menu ...

  3. js script type 部分属性值分析

    1. text/javascript: (1)<script type="text/javascript" src="Js/jquery-1.10.2.min.js ...

  4. python基础--结构篇

    在C/C++/Java中,main是程序执行的起点,Python中,也有类似的运行机制,但方式却截然不同: Python使用缩进对齐组织代码的执行,所有没有缩进的代码(非函数定义和类定义),都会在载入 ...

  5. 【CodeForces】582 C. Superior Periodic Subarrays

    [题目]C. Superior Periodic Subarrays [题意]给定循环节长度为n的无限循环数列,定义(l,s)表示起点为l的长度为s的子串,(l,s)合法要求将子串从该起点开始以s为循 ...

  6. 【51NOD-0】1012 最小公倍数LCM

    [算法]欧几里德算法 #include<cstdio> int gcd(int a,int b) {?a:gcd(b,a%b);} int main() { int a,b; scanf( ...

  7. quick-cocos2dx 悬浮节点(NotificationNode)

    cocos2dx 开发游戏时,有时某些节点不需要随着场景的切换而销毁.但cocos2dx的机制只允许同时只有一个运行的场景,如果你的所有节点都是依附于这个场景的,那场景的切换必然带来节点的销毁. 比如 ...

  8. java 连接MySQL的代码

    1.java connect MySQL as conding. https://www.cnblogs.com/centor/p/6142775.html

  9. VMware 12安装虚拟机Mac OS X 10.10使用小技巧(虚拟机Mac OS X 10.10时间设置,虚拟机Mac OS X 10.10通过代理上网,Mac OS X 10.10虚拟机优化,VMware虚拟机相互复制)

    1:修改Mac OS 系统时间 2:Mac OS系统 通过代理上网 VMware 12安装Mac OS X 10.10虚拟机优化心得 虚拟显卡硬伤,所以必须要优化下才能用,优化的原则就是能精简的精简, ...

  10. bzoj 3524 可持久化线段树

    我们可以先离散化,然后建立权值的可持久化线段树,记录每个数出现的次数,对于区间询问直接判断左右儿子的cnt是不是大于(r-k+1)/2,然后递归到最后一层要是还是大于就有,否则不存在. 反思:挺简单一 ...