持续集成与自动化部署 - 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.mzph.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 或…