Window从零开始搭建Jenkins+SonarQube持续集成平台

Windows从零搭建 Jenkins + SnoarQube (持续集成平台)

此文档暂时不包含发布相关知识点。

  • 持续集成环境:Jenkins
    • 所需系统环境: java 8 及以上,配置 java 相关环境变量(此处略过)
  • 代码托管:Git 2.22 或者 gitlab
  • 审查工具:SonarQube
    • 该工具由两部分组成,分别是 SonarQube本身(即是审查服务器),和 sonar-scanner(审查服务端)

      SonarQube和sonar-scanner的关系就像是 github 官网和我们本地的 git 软件的关系

    • snoar-scanner = sonar-runner 是同一个软件在不同版本下的名字,网上的教程两者基本上是通用的


资源下载

一.启动 Jenkins
  • 1.下载 Jenkins 的 war 包
  • 2.在 war 包所在目录执行 java -jar jenkins.war --httpPort=8089
  • 3.打开浏览器输入网址 localhost:8089 我们就能发现 Jenkins 已经跑起来了

jenkins1.png


二.启动 SonarQube
  • 1.首先需要安装 MySql 数据库(为了方便可配置mysql相关环境变量,同时第一次进入mysql需要修改密码,此处都略过,百度一下)

    root 登录 mysql,创建 sonar 数据库和用户授权。

        CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; 
        CREATE USER 'sonar' IDENTIFIED BY 'sonar';
        GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
        GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
        FLUSH PRIVILEGES;
  • 2.在路径下的 conf 文件夹下修改 sonar.properties

    sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
    sonar.jdbc.username=snoar
    sonar.jdbc.password=snoar
    sonar.sourceEncoding=UTF-8
  • 3.之后打开 bin 目录下对应的 StartSnoar.bat 就可以启动 Snoar 服务器了。可通过浏览器 localhost:9000 查看

    默认的 SnoarQube 账号密码为 admin/admin.(附:5.6版本的 SonarQube 汉化需要去找 github 发布的对应 tag 版本手动本地安装)

    jenkins2.png
    jenkins3.png


三.配置 sonar-scanner(SonarQube和sonar-scanner的关系就像是 github 官网和我们本地的 git 软件的关系)
  • 1.配置 sonar-scanner 目录下 conf 中的 snoar-scanner.properties

    sonar.jdbc.url=jdbc:mysql://172.16.24.12:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
    sonar.jdbc.username=root
    sonar.jdbc.password=root
  • 2.配置环境变量使得 cmd 下任何路径都可使用 sonar-scanner 命令

    cmd 下输入 snoar-scanner -version 有显示即为成功

    jenkins4.png

  • 3.然后我们去找个我们 git 项目的文件夹里,创建 sonar-project.properties

    # must be unique in a given SonarQube instance
    sonar.projectKey=my:project
    
    # this is the name displayed in the SonarQube UI
    sonar.projectName=apiautocore
    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=src
    
    # Encoding of the source code. Default is default system encoding
    sonar.sourceEncoding=UTF-8

    jenkins5.png

  • 4.因为之前配了环境变量,这边跑命令即可。

    jenkins6.png

  • 5.然后去我们前面所说的 SonarQube服务器 localhost:9000 验收结果即可。

    这里发现没有检测到 .vue 文件,原因是插件需要更新,在 SonarQube 服务器端更新下 SonarJS 插件到 3.0 版本以上即可。

    jenkins7.png

转载于:https://www.cnblogs.com/can-i-do/p/11173669.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值