zoukankan      html  css  js  c++  java
  • jenkins+sonar+钉钉 发布.net

    jenkins发布.net 请参照

    https://www.cnblogs.com/xiaoyou2018/p/12012512.html

    C#语言接入Sonar代码静态扫描相较于Java、Python来说,相对麻烦一些。Sonar检测C#代码时需要预先编译,而且C#代码必须用MSbuid进行编译,如果需要使用SonarQube对C#进行代码质量分析,则需要下载Sonar-Scanner-MSBuild和MSBuild,其中要求MSBuild在V14.0以上

    一、环境

    jenkins:2.190.3

    sonarqube:sonarqube-8.2.0.32929

    sonar-scanner-msbuild:4.3.1.1372-net46

    JDK  :jdk13 (sonarqube8.0及以上版本需要jdk11以上)

    数据库: sqlserver2014 (sonarqube8.0及以上版本不支持mysql数据库)

     安装包:

    链接:https://pan.baidu.com/s/1sgegjpFnBnXB2i3gxITa5Q
    提取码:qtno

    二、SonarQube简介

    Sonar (SonarQube)是一个开源平台,用于管理源代码的质量。 Sonar 不只是一个质量数据报告工具,更是代码质量管理平台。 支持java, JavaScrip, Scala 等等二十几种编程语言的代码质量管理与检测。 SonarQube®是一种自动代码审查工具,用于检测代码中的错误,漏洞和代码异味。它可以与您现有的工作流程集成,以便在项目分支和拉取请求之间进行连续的代码检查。
     

    三、安装

    环境安装包括:Java-JDK,SonarQube、sonar-scanner for MsBuild

    1、jdk113

    官网下载地址JDK官网下载

    下载完成后,双击安装包即可安装。

    • 单击下一步

    单击下一步

    • 选择安装路径   

    选择安装路径

    更改路径

                 如果不需要修改则直接下一步,需要更改路径则点击更改,选择你要安装的路径即可。 

    • 安装完成

    安装完成

    配置环境变量

     新建系统环境变量JAVA_HOME  在下方的系统环境变量(S)区域,点击新建,变量名为JAVA_HOME,变量值是你自己的JDK安装路径。

    在Path中增加%JAVA_HOME%in 双击Path,点击新建,输入

    %JAVA_HOME%in;

     验证:

    2、数据库sqlserver2014

    安装过程不赘述

    参考:https://www.cnblogs.com/advLuo/p/11455942.html

    新建sonar 库

    注意库的排列顺序

     手动修改数据库的排列顺序

    ALTER DATABASE sonar COLLATE Chinese_PRC_CS_AS

    完成后记得重启数据库

    用户:jason

    密码:123456

    3、sonarqube安装

    下载地址:SonarQube Download

    下载安装包,解压至指定目录(目录不能是数字目录)

    进入bin目录,再进入windows-x86-64

    运行StartSnoar.bat,完成SonarQube安装

    如果JDK安装和环境变量正常,SonarQube安装成功如下

    浏览器打开SonarQube配置默认串口9000的网站:http://localhost:9000/about,登录账号密码默认为admin

    想配置端口可通过cC:sonarqube-8.2.0.32929confsonar.properties配置,去掉#,端口口改成其他数字

    汉化

     

     记得重启sonarqube(关掉java进程,重新运行StartSonar.bat)

     设置SonarQube配置文件sonar.properties

    C:sonarqube-8.2.0.32929confsonar.properties

    sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar
    sonar.jdbc.username=jason
    sonar.jdbc.password=12345678
    sonar.sorceEncoding=UTF-8
    
    #sonar登录用户
    sonar.login=admin
    sonar.password=admin

    需要重启生效(关掉java进程,重新运行StartSonar.bat)

    启动失败的话,查看C:sonarqube-8.2.0.32929logsweb.log  排查

    4、解压配置sonar-scanner-msbuild-4.3.1.1372-net46

    C:sonar-scanner-msbuild-4.3.1.1372-net46SonarQube.Analysis.xml

    <?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 SonarScanner.MSBuild.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">http://localhost:9000</Property>
    
      <Property Name="sonar.login">admin</Property>
      <Property Name="sonar.password">admin</Property>
      -->
    
      <!-- Required only for versions of SonarQube prior to 5.2 -->
      <!--
      <Property Name="sonar.jdbc.url">jdbc:sqlserver://localhost;databaseName=sonar</Property>
      <Property Name="sonar.jdbc.username">jason</Property>
      <Property Name="sonar.jdbc.password">12345678</Property>
      -->
    
    </SonarQubeAnalysisProperties>

    测试扫描,Sonar+命令行分析C#代码

    打开CMD,切换到指定的项目根目录,必须和.sln或者.csproj同级目录。例如以C:Usersjenkins.jenkinsworkspacewhenchattest20.APP接口站点测试    项目为例,如下图所示。

    依次输入如下三个命令:

    SonarQube.Scanner.MSBuild.exe begin /k:"APP接口站点测试" /n:"APP接口站点测试" /v:"1.0"
    MSBuild.exe /t:Rebuild
    SonarScanner.MSBuild.exe end

    命令说明:

    SonarQube.Scanner.MSBuild.exe begin /k:"项目键值" /n:"项目名" /v:"1.0"
    MSBuild.exe /t:Rebuild
    SonarScanner.MSBuild.exe end

    参数说明:

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

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

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

    5、关联jenkins

    (1)jenkins安装插件:SonarQube Scanner for Jenkins

    (2)jenkins添加sonar凭据

    jenkins管理--凭据--系统--全局凭据--添加凭据

    类型:secret text

    secret: sonar账户的令牌

    在配置页对SonarQube servers进行配置:

    jenkins管理-系统管理

    在配置页对Sonarscanner-msbuild进行配置:

     系统--全局工具管理

     对jenkins项目进行配置,新增构建步骤

    jenkins关联钉钉

    安装钉钉插件 dingtalk(安装完后需要重启jenkins)

    在页面配置钉钉

     系统--系统管理

     在jenkins项目配置里面增加钉钉配置

    发布成功后钉钉会发送消息

     参考:

    https://testerhome.com/topics/20767
    https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/
    https://blog.csdn.net/weixin_44903147/article/details/98339110
    https://www.cnblogs.com/qfdmmh/p/10998119.html
    https://aijishu.com/a/1060000000096609 踩坑
    http://m.shangdixinxi.com/detail-1020462.html
    https://www.cnblogs.com/advLuo/p/11455942.html 安装

    dk13安装

    https://blog.csdn.net/hunter_max/article/details/102880735

  • 相关阅读:
    BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序 总结
    修改sepolicy后编译出现‘Error while expanding policy’【转】
    memalign的作用【转】
    Linux 使用statvfs读取文件系统信息
    strerror函数的总结【转】
    UFS 介绍 1[【转】
    EMMC 介绍【转】
    何为TLC、MLC、SLC?【转】
    赞 ( 84 ) 微信好友 新浪微博 QQ空间 180 SSD故事会(14):怕TLC因为你不了解!【转】
    RPMB分区介绍【转】
  • 原文地址:https://www.cnblogs.com/xiaoyou2018/p/12486677.html
Copyright © 2011-2022 走看看