持續集成與自動化部署 - jenkins sonar代碼質量管理平臺 部署和基礎使用(五)...

1 jenkins

安裝參考鏈接

1.1 安裝jenkins

[root@test-node3 ~]# yum install -y java-1.8.0
[root@test-node3 ~]# cd /etc/yum.repos.d/
[root@test-node3 yum.repos.d]# wget http://pkg.jenkins.io/redhat/jenkins.repo
[root@test-node3 yum.repos.d]# rpm --import http://pkg.jenkins.io/redhat/jenkins.io.key
[root@test-node3 yum.repos.d]# yum install -y jenkins
[root@test-node3 yum.repos.d]# systemctl start jenkins

1.2 安裝jenkins插件

[root@test-node3 ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
d71307d2e9764f428d853bc49ac6b5ea

持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

選擇默認安裝,會安裝通用的插件,剩下的在需要用的的時候再安裝。
持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

等待安裝完成
持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)
設置用戶名密碼
user:admin
key: 123..abc
持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)
持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

1.3 新建一個任務

[root@test-node3 ~]# usermod -s /bin/bash jenkins-bash-4.2$ ssh-copy-id -i .ssh/id_rsa.pub www@10.0.0.204
The authenticity of host '10.0.0.204 (10.0.0.204)' can't be established.
ECDSA key fingerprint is cd:9c:13:52:1a:96:c6:2b:4c:0c:5a:83:f6:94:01:48.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
www@10.0.0.204's password: Number of key(s) added: 1Now try logging into the machine, with:   "ssh 'www@10.0.0.204'"
and check to make sure that only the key(s) you wanted were added.-bash-4.2$ 
-bash-4.2$ ssh www@10.0.0.204
Last login: Wed Apr 12 09:33:40 2017
[www@salt-node4 ~]$ 
[www@salt-node4 ~]$ logout
Connection to 10.0.0.204 closed.

持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)
持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

測試
點擊立即構建
持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)
自動部署完成。
持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

1.4 jenkins安裝gitlab插件

注:jenkins填寫的是私鑰(gitlab服務器上填寫的是公鑰 - 步驟同gitlab添加ssh 公鑰,jenkins用ssh協議到gitlab上面去拉取代碼。)

持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

2. 代碼質量管理 - sonar

Sonar 是一個用于代碼質量管理的開放平臺。通過插件機制,Sonar 可以集成不同的測試工具,代碼分析工具,以及持續集成工具。與持續集成工具(例如 Hudson/Jenkins 等)不同,Sonar 并不是簡單地把不同的代碼檢查工具結果(例如 FindBugs,PMD 等)直接顯示在 Web 頁面上,而是通過不同的插件對這些結果進行再加工處理,通過量化的方式度量代碼質量的變化,從而可以方便地對不同規模和種類的工程進行代碼質量管理。
在對其他工具的支持方面,Sonar 不僅提供了對 IDE 的支持,可以在 Eclipse 和 IntelliJ IDEA 這些工具里聯機查看結果;同時 Sonar 還對大量的持續集成工具提供了接口支持,可以很方便地在持續集成中使用 Sonar。
此外,Sonar 的插件還可以對 Java 以外的其他編程語言提供支持,對國際化以及報告文檔化也有良好的支持

2.1 部署sonar

注:1 sonar 需要安裝數據庫版本為mysql 5.6及以上。 2 需要java環境,java版本為1.8以上

mysql 5.6 Yum源
https://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
yum -y install  mysql-community-server

[sonar部署參考鏈接] (https://www.unixhot.com/article/56)

2.1.1 下載 安裝 sonar源碼

[root@test-node3 ~]# cd /server/tools/
[root@test-node3 ~]# wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.6.zip
[root@test-node3 tools]#  unzip sonarqube-5.6.zip
[root@test-node3 tools]# mv sonarqube-5.6 /usr/local/
[root@test-node3 tools]# ln -s /usr/local/sonarqube-5.6/ /usr/local/sonarqube

2.1.2 準備Sonar數據庫

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar@pw';
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar@pw';
FLUSH PRIVILEGES;
[root@test-node3 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.36 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.01 sec)mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar@pw';
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar@pw';
Query OK, 0 rows affected (0.06 sec)mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar@pw';
Query OK, 0 rows affected (0.00 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)mysql> 

2.1.3 配置Sonar

[root@test-node3 tools]# cd /usr/local/sonarqube/conf/
[root@test-node3 conf]# vim sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar@pw
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

2.1.4 啟動Sonar

如果沒有正常啟動,查看日志一般就可以解決。

可以在Sonar的配置文件來配置Sonar Web監聽的IP地址和端口,默認是9000端口。

[root@test-node3 conf]# vim sonar.properties
sonar.web.host=0.0.0.0
sonar.web.port=9000[root@test-node3 conf]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh start
[root@test-node3 logs]# netstat -tnlpua|grep 9000
tcp        0      0 0.0.0.0:9000            0.0.0.0:*               LISTEN      44042/java  

2.2 安裝語言插件

分析什么語言就下載對應的語言插件。

web界面 用戶名密碼,默認為:admin/admin

步驟:
方法一 web界面安裝

Administration --> System -->  Update Center --> Available  搜索chiness Pack 點擊install。安裝完成之后需要重啟sonar
[root@test-node3 plugins]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh restart

持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

方法二 下載jar包進行替換
下載的連接可以根據在web界面安裝插件的失敗提醒來下載,如果不能下載,用迅雷下載。

https://github.com/SonarQubeCommunity/sonar-l10n-zh/releaseshttps://github.com/SonarQubeCommunity/sonar-l10n-zh/releases/download/sonar-l10n-zh-plugin-1.11/sonar-l10n-zh-plugin-1.11.jar
下載到/usr/local/sonarqube/extensions/plugins目錄需要重啟才能生效
[root@test-node3 plugins]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh restart

持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

2.3 安裝sonar 代碼掃描工具插件

參考鏈接

2.3.1 下載安裝源碼文件

[root@test-node3 plugins]# cd /server/tools/
[root@test-node3 tools]# wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.6.1.zip  
[root@test-node3 tools]# cp -rf sonar-scanner-2.6.1 /usr/local/sonar-scanner

2.3.2 修改配置文件

[root@test-node3 tools]# cd /usr/local/sonar-scanner/conf
[root@test-node3 conf]# cat sonar-scanner.properties #----- Default SonarQube server
sonar.host.url=http://localhost:9000#----- Default source code encoding
sonar.sourceEncoding=UTF-8#----- Global database settings (not used for SonarQube 5.2+)
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar@pw#----- MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

2.3.3 下載測試代碼進行掃描

掃描的是php語言,因此需要php語言的插件SonarPHP

[root@test-node3 tools]# unzip sonar-examples-4.5.zip
[root@test-node3 tools]#  cd /server/tools/sonar-examples-4.5/projects/languages/php/php-sonar-runner[root@test-node3 php-sonar-runner]# /usr/local/sonar-scanner/bin/sonar-scanner
.....
INFO: Sensor PHP sensor
INFO: 1 source files to be analyzed
INFO: 1/1 source files have been analyzed
INFO: No PHPUnit test report provided (see 'sonar.php.tests.reportPath' property)
INFO: No PHPUnit unit test coverage report provided (see 'sonar.php.coverage.reportPath' property)
INFO: No PHPUnit integration test coverage report provided (see 'sonar.php.coverage.itReportPath' property)
INFO: No PHPUnit overall coverage report provided (see 'sonar.php.coverage.overallReportPath' property)
INFO: Sensor PHP sensor (done) | time=1030ms
INFO: Sensor Analyzer for "php.ini" files
INFO: Sensor Analyzer for "php.ini" files (done) | time=6ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=24ms
INFO: Sensor Code Colorizer Sensor
INFO: Sensor Code Colorizer Sensor (done) | time=1ms
INFO: Sensor CPD Block Indexer
INFO: DefaultCpdBlockIndexer is used for php
INFO: Sensor CPD Block Indexer (done) | time=0ms
INFO: Calculating CPD for 1 files
INFO: CPD calculation finished
INFO: Analysis report generated in 265ms, dir size=22 KB
INFO: Analysis reports compressed in 14ms, zip size=9 KB
INFO: Analysis report uploaded in 472ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/org.sonarqube:php-simple-sq-scanner
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AVthpV-GZk_1lOkjIdp8
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 16.131s
INFO: Final Memory: 43M/117M

注意:這里面有一個文件需要定義的,告訴sonar 語言,版本,及相關。

[root@test-node3 php-sonar-runner]# cat sonar-project.properties 
# Required metadata
sonar.projectKey=org.sonarqube:php-simple-sq-scanner
sonar.projectName=PHP :: Simple Project :: SonarQube Scanner
sonar.projectVersion=1.0# Comma-separated paths to directories with sources (required)
sonar.sources=src# Language
sonar.language=php# Encoding of the source files
sonar.sourceEncoding=UTF-8

持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

持續集成與自動化部署 -  jenkins & sonar代碼質量管理平臺 部署和基礎使用(五)

轉載于:https://blog.51cto.com/damaicha/2118745

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/451731.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/451731.shtml
英文地址,請注明出處:http://en.pswp.cn/news/451731.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【轉】數學與編程——求余、取模運算及其性質

一、求余運算(Remainder) (參考維基百科: http://zh.wikipedia.org/wiki/余數 http://en.wikipedia.org/wiki/Remainder http://en.wikipedia.org/wiki/Euclidean_divisionhttp://zh.wikipedia.org/wiki/同余) Euclid…

javax.net.ssl.SSLException MESSAGE: closing inbound before receiving peer‘s close_notify

1. 問題描述: ** BEGIN NESTED EXCEPTION ** javax.net.ssl.SSLException MESSAGE: closing inbound before receiving peers close_notifySTACKTRACE:javax.net.ssl.SSLException: closing inbound before receiving peers close_notifyat sun.security.ssl.Alert.…

提高虛擬機運行速度方法

原網頁 要我注冊才能復制... 所以我只記錄了那個網址,我的情況是啟動很慢,照作后有效果。 該網址:提高虛擬機速度

InputStream 、 InputStreamReader和BufferedReader

InputStream : 是所有字節輸入流的超類,一般使用它的子類:FileInputStream等,它能輸出字節流;InputStreamReader : 是字節流與字符流之間的橋梁,能將字節流輸出為字符流,并且能為字節…

多線程原理分析面試題理解

系列前言 本系列是本人參加微軟亞洲研究院,騰訊研究院,迅雷面試時整理的,另外也加入一些其它IT公司如百度,阿里巴巴的筆試面試題目,因此具有很強的針對性。系列中不但會詳細講解多線程同步互斥的各種“招式”&#xff…

Could not load driverClass “com.mysql.jdbc.Driver“

1. 問題描述 Could not load driverClass “com.mysql.jdbc.Driver” 2. 解決辦法 檢查是否成功導入了mysql的jdbc的jar包 導入后成功解決 參考文獻: https://blog.csdn.net/weixin_43433032/article/details/98494228 感謝作者分享!

luogu2034

/** 正難則反* f[i] 表示前 i 個數中被刪除的數的最小和* f[i] min(f[j]) num, i - k 1 < j < i;* 單調隊列維護 */ #include <bits/stdc.h>#define LL long longconst int N 1e5 10;LL tot, d, n, k; LL p[N], head 1, tail 1; LL q[N], f[N], ans;int mai…

Django的models操作

一、先看單表操作 增 方式1&#xff1a; models.book.objects.create(Book_name "aaa",Book_info "bbb",Book_price "ccc",Book_num "ddd")方式2&#xff1a;用2個*號傳遞一個字典進去  book_info {"Book_name":"…

ngingx安裝錯誤 ./configure: error: the HTTP rewrite module requires the PCRE library.

前些天發現了一個巨牛的人工智能學習網站&#xff0c;通俗易懂&#xff0c;風趣幽默&#xff0c;忍不住分享一下給大家。點擊跳轉到教程。 1. ngnix 安裝報錯&#xff1a; 2. 解決&#xff1a; 安裝pcre-devel解決問題&#xff0c;運行命令 yum -y install pcre-devel 3.…

32--數組中重復的數字

1. 問題描述 找出數組中重復的數字。 在一個長度為 n 的數組 nums 里的所有數字都在 0&#xff5e;n-1 的范圍內。數組中某些數字是重復的&#xff0c;但不知道有幾個數字重復了&#xff0c;也不知道每個數字重復了幾次。請找出數組中任意一個重復的數字。 示例 1&#xff1…

實習期間的一些思考整理(3)2018.4.12~4.13

青云訣游戲體驗日報-2018.4.12 今日關鍵點&#xff1a;核心玩法 青云訣的核心玩法是“戰斗”、“成長”、“探索”&#xff08;這三點也是RPG類型的要素&#xff09;&#xff0c;側重于成長。 我是這樣想的&#xff0c;要想找出核心玩法是什么&#xff0c;就要看哪些玩法沒了&a…

整理的最全 python常見面試題(基本必考)

訪問flyai.club&#xff0c;一鍵創建你的人工智能項目作者&#xff1a;大蛇王https://blog.csdn.net/t8116189520/article/details/801655891、大數據的文件讀取① 利用生成器generator②迭代器進行迭代遍歷&#xff1a;for line in file2、迭代器和生成器的區別1)迭代器是一個…

Nginx安裝手冊(摘自入云龍老師教案,親測可用)

前些天發現了一個巨牛的人工智能學習網站&#xff0c;通俗易懂&#xff0c;風趣幽默&#xff0c;忍不住分享一下給大家。點擊跳轉到教程。 Nginx安裝手冊 一、 nginx安裝環境 nginx是C語言開發&#xff0c;建議在linux上運行&#xff0c;本教程使用Centos6.5作為安裝環境。 …

33--二維數組中的查找

1.問題描述 在一個 n * m 的二維數組中&#xff0c;每一行都按照從左到右遞增的順序排序&#xff0c;每一列都按照從上到下遞增的順序排序。請完成一個函數&#xff0c;輸入這樣的一個二維數組和一個整數&#xff0c;判斷數組中是否含有該整數。 示例: 現有矩陣 matrix 如下&…

XML Schema是什么

XML Schema 本身也是一種XML構造&#xff0c;它用來描述[哪個元素&#xff0c;在什么時候出現]&#xff0c;[該元素具有什么樣的屬性]等等&#xff0c;也就是說&#xff0c;XML Schema是對XML的樹形構造加以描述說明的一種語言。原本&#xff0c;使用DTD對XML的樹形構造加以描述…

js之base64上傳圖片

首先要搭建好springmvc&#xff0c;詳見https://www.cnblogs.com/zzb-yp/p/9295397.html 整體思路&#xff1a;前端代碼包括顯示和傳參&#xff08;這里的參數主要就是圖片的base64字符串&#xff09;&#xff0c;顯示主體部分是type“file”類型的input組件和一個提交按鈕 …

一些常用軟件的網絡端口協議分類介紹

最近有朋友請教我有關實現校園局域網視頻功能軟件的編寫問題&#xff0c;涉及到端口有關的知識&#xff0c;自己查了一些資料&#xff0c;發現這篇文章總結得比較不錯&#xff0c;常用軟件涵蓋得比較豐富&#xff0c;很實用&#xff0c;需要用到的時候可以查閱。于是決定將這篇…

WPF 使用皮膚影響按鈕自定義

在WPF項目中使用了 Theme的皮膚后&#xff0c;發現自定義的按鈕全部都是 皮膚里面的樣式&#xff0c;如下圖&#xff1a; 要自定義樣式&#xff0c;只有不給按鈕使用皮膚樣式。 如果想給某一個控件使用樣式&#xff0c;在前端Xaml的控件中&#xff0c;設置一下屬性即可&#xf…

各種數據庫對應的jar包、驅動類名和URL格式

見&#xff1a;http://blog.csdn.net/xuguiyi100/article/details/7970379 maven/Java/web/bootstrapQQ群&#xff1a;566862629。希望更多人一起幫助我學習。 1.1. 各種數據庫對應的jar包 具體如下&#xff1a; 數據庫類型 對應的Jar文件 Oracle 8i classes12.zip 或…