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

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

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

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

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

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


资源下载


一.启动 Jenkins

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


二.启动 SonarQube

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

    root 登陆 mysql,建立 sonar 数据库和用户受权。sql

        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 查看windows

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



三.配置 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 有显示即为成功

  • 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

  • 4.由于以前配了环境变量,这边跑命令便可。

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

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

相关文章
相关标签/搜索