<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### 理論知識 #### SonarQube 與 Jenkins 簡 介 SonarQube 是一個開源的代碼質量分析平臺,便于管理代碼的質量,可檢查出項目代碼的漏洞和潛在的邏輯問題。同時,它提供了豐富的插件,支持多種語言的檢測, 如 Java、Python、Groovy、C、C++等幾十種編程語言的檢測。它主要的核心價值體現在如下幾個方面: - 檢查代碼是否遵循編程標準:如命名規范,編寫的規范等。 - 檢查設計存在的潛在缺陷:SonarQube 通過插件 Findbugs、Checkstyle 等工具檢測代碼存在的缺陷。 - 檢測代碼的重復代碼量:SonarQube 可以展示項目中存在大量復制粘貼的代碼。 - 檢測代碼中注釋的程度:源碼注釋過多或者太少都不好,影響程序的可讀可理解性。 - 檢測代碼中包、類之間的關系:分析類之間的關系是否合理,復雜度情況。 ** SonarQube 平臺是由4個部分組成:** - SonarQube Server - SonarQube Database - SonarQube Plugins - SonarQube Scanner 參考https://www.ibm.com/developerworks/cn/devops/1612_qusm_jenkins/index.html 感謝《IBM的曲世明和陳計云》 #### SonarQube Scanner原理 SonarQube Scanner,作為代碼掃描的工具,通過它,將項目的代碼讀取并發送至SonarQube服務器中,才能讓SonarQube進行代碼分析。 可以認為SonarQube Scanner就是SonarQube的客戶端。SonarQube Scanner很方便和不同類型的構建工具進行整合 參考http://aoyouzi.iteye.com/blog/2294992 感謝《aoyouzi》 #### 功能介紹(個人理解) - Jenkins - SonarQube Server(接收代碼,進行分析) - SonarQube Scanner for Jenkins(Jenkins用來調用SonarQube Scanner的插件) - SonarQube Scanner(SonarQube的客戶端,將讀取的代碼發送到SonarQube Server) ### SonarQube Server服務部署 #### 下載SonarQube Server(5.6.6版本) https://www.SonarQube.org/downloads/ #### 安裝SonarQube Server 1. 部署Centos 7.3 x86_64 2. 部署JDK1.8(略) 3. 部署MysQL5.7(略) 4. 創建MySQL用戶 ```shell create user 'sonar'@'192.168.0.231' identified by 'sonar2017'; CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; grant all privileges on sonar.* to 'sonar'@'192.168.0.231'; ``` 4. 安裝SonarQube(以前叫sonar)上傳sonar到/opt目錄下 ```shell unzip SonarQube-5.6.6.zip mv SonarQube-5.6.6 /app/ ln -s SonarQube-5.6.6 SonarQube ``` 5.編輯配置文件(/app/SonarQube/conf/sonar.properties) ```shell #grep -vE '#|^.$' /app/SonarQube/conf/sonar.properties sonar.jdbc.username=sonar sonar.jdbc.password=sonar2017 sonar.jdbc.url=jdbc:mysql://192.168.0.231:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance sonar.web.host=192.168.0.231 sonar.web.context=/sonar sonar.web.port=9000 sonar.log.level=INFO sonar.path.logs=logs ``` 備注:sonar.web.context=/sonar 是訪問地址后綴,配置后訪問地址變為,http://192.168.0.231:9000/sonar #### SonarQube Server漢化(注意:不同版本,漢化包不同) [SonarQube 5.6.6中文包地址](https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.15/sonar-l10n-zh-plugin-1.15.jar "Sonar 5.6.6中文包地址") 上傳到/app/SonarQube/extensions/plugins #### 啟動SonarQube - 啟動 ```shell /app/SonarQube/bin/linux-x86-64/sonar.sh restart ``` - 看日志 ```shell tail -f /app/SonarQube/logs/sonar.log ``` - console模式 ```shell /app/SonarQube/bin/linux-x86-64/sonar.sh console ``` #### 登錄,并修改密碼,創建token(后面jenkins要用) - 登錄地址:http://192.168.0.231:9000/sonar 默認用戶名密碼admin/admin - 修改管理員密碼 login-->配置-->權限-->用戶-->點擊administraotr后面的鎖圖標 - 創建一個用戶ding login-->配置-->權限-->用戶-->token-->update token-->Generate Tokens(輸入ding)-->generate 記錄下token 參考文章:http://www.cnblogs.com/westfly/p/6098100.html 感謝《westfly》 ### Jenkins和SonarQube Server集成 #### 安裝SonarQube Scanner for Jenkins插件 系統管理-->管理插件-->SonarQube Scanner for Jenkins-->安裝 #### 配置SonarQube Server的連接 系統管理-->系統設置-->配置SonarQube servers ```shell Environment variables 勾選 SonarQube installations name:隨便寫 Server URL:http://192.168.0.231:9000/sonar Server version:5.3 or higher 注:5.1 or higher不支持token方式,如果寫了數據庫信息,在輸出中會提示這個特性已被忽略,不建議使用。 Server authentication token:你懂的。 ``` #### 配置項目構建過程中的選項,增加SonarQube Scanner 系統管理-->Global Tool Configuration SonarQube Scanner for MSBuild(Microsoft 和 Visual Studio的生成系統,不配置) SonarQube Scanner(我們配置這個) ```shell name:隨便填 自動安裝:勾選 選擇版本:最新(3.0.3.778) ``` #### 項目中配置SonarQube Scanner參數(讀哪的代碼、什么語言等) 項目-->增加構建步驟-->Execute SonarQube Scanner JDK:選jdk1.8(提前配置) Analysis Properties: ```shell sonar.language=java sonar.sources=$WORKSPACE/ sonar.projectName=ding sonar.projectKey=ding sonar.projectVersion=1.0 sonar.sourceEncoding=UTF-8 ``` ```shell sonar.language=java 開發語言(匹配Server上的語言規則) sonar.sources=$WORKSPACE/ RPM包安裝后,位置是/var/lib/jenkins/workspace/ 項目都會下載到這里 sonar.projectName=ding 項目名稱,回去里面讀src sonar.projectKey=ding 唯一的項目Key,SonarQube Server上作為唯一標識,生成鏈接 sonar.projectVersion=1.0 版本:不太理解,強制要求 sonar.sourceEncoding=UTF-8 開發代碼字符集 ``` 參考鏈接:https://docs.SonarQube.org/display/SCAN/Analyzing+with+SonarQube+Scanner ### 故障處理 #### 故障1:項目中配置SonarQube Scanner的Task to run為ding,就報這個錯,去掉就可以了 ```shell 13:53:22.236 ERROR: Error during SonarQube Scanner execution Task 'ding' does not exist. Please use 'list' task to see all available tasks. 13:53:22.236 DEBUG: Execution getVersion 13:53:22.236 DEBUG: Execution stop ERROR: SonarQube scanner exited with non-zero code: 1 Sending e-mails to: dinghe@ding.com Finished: FAILURE ``` **解決** 去掉SonarQube Scanner的Task to run中的內容 #### 故障2: E170001 **報錯** ```shell Caused by: org.tmatesoft.svn.core.SVNAuthenticationException: svn: E170001: Authentication required for '<http://192.168.0.250:80> VisualSVN Server' ``` **解決:** 登錄SonarQube Server-->配置-->SCM-->設置為是(關閉SCM) #### 故障2:SonarQube安裝完后出現SonarQube is under maintenance. Please check back later. ```shell SonarQube在安裝完后運行:192.168.0.235:9000出現如下提示 SonarQube is under maintenance. Please check back later. Whilst waiting, you might want to check new plugins to extend the current functionality. If you are an administrator and have no idea why this message is showing, you should read the upgrade guide 這個需要安裝完后先運行http://192.168.0.235:9000/setup 更新下 SonarQube ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看