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 版本以上便可。

相關文章
相關標籤/搜索