码迷,mamicode.com
首页 > Web开发 > 详细

【持续集成】GIT+jenkins+snoar——jenkins发布php、maven项目

时间:2017-05-25 15:38:54      阅读:1237      评论:0      收藏:0      [点我收藏+]

标签:cache   jenkins   pat   read   status   文章   浏览器   first   size   

 

一.持续集成

1.1 什么是持续集成?

  continuous integration (CI),持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通常每个成员,每天至少集成一次,也就意味着每天可能会发生多次集成。每次集成都通过自动化构建(包括编译、发布、自动化测试)来验证,从而尽快的发现集成错误。许多团队发现这个过程可以大大减少集成的问题,让团队能够更快的开发内聚的软件。

1.2 持续集成最佳实践

  • 维护一个单一的代码库
  • 使构建自动化
  • 执行测试是构建的一部分
  • 集成日志及历史记录
  • 使用统一的依赖包管理库
  • 每天至少集成一次

二. jenkins

2.1 什么是jenkins

  Jenkins is an automation engine with an unparalleled plugin ecosystem to support all of your favorite tools in your delivery pipelines,wether your goal is continuous integration,automated testing,or continuous delivery.

  Jenkins 是持续集成、自动测试、持续部署的超级引擎,支持自定义工具集、多种交付通道。

2.2 安装jenkins

 

 1 #安装依赖
 2 [root@linux-node2 ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
 3 #下载Jenkins包
 4 [root@linux-node2 src]# wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.32.3-1.1.noarch.rpm
 5 #rpm安装
 6 [root@linux-node2 src]# rpm -ivh jenkins-2.32.3-1.1.noarch.rpm
 7 #启动Jenkins
 8 [root@linux-node2 src]# systemctl start jenkins
 9 #查看端口是否启动
10 [root@linux-node2 src]# netstat -lntup
  tcp6       0      0 :::8080                 :::*                    LISTEN      17737/java

 

2.3 访问jenkins页面

打开浏览器:http://192.168.56.12:8080

技术分享

输入密码:

1 #查看页面上提供的该文件内容(默认密码)
2 [root@linux-node2 src]# cat /var/lib/jenkins/secrets/initialAdminPassword
3 8afe5fe9dd7a48e0a1817b287b627dfc

技术分享

选择安装默认插件或者直接关闭

技术分享

技术分享

技术分享

看到以上界面,Jenkins就已成功安装

2.4 安装Jenkins插件

1 #将插件移动到指定目录下
2 [root@linux-node2 src]# mv plugins.tar.gz  /var/lib/jenkins/
3 #进入指定目录
4 [root@linux-node2 src]# cd /var/lib/jenkins/
5 #解压插件
6 [root@linux-node2 jenkins]# tar xf plugins.tar.gz
7 #授权
8 [root@linux-node2 jenkins]# chown -R jenkins.jenkins plugins
9 #重启服务 10 [root@linux-node2 plugins]# systemctl restart jenkins

技术分享

技术分享

技术分享

2.5 Jenkins配置

1 #编辑配置文件
2 [root@linux-node2 jenkins]# vim /etc/sysconfig/jenkins
3 #生产中建议使用Jenkins
4 29 JENKINS_USER="root"

2.6 Jenkins目录

/var/lib/jenkins            主目录

/etc/init.d/jenkins           启动文件

/var/cache/jenkins/           程序文件

/var/log/jenkins/            日志文件

三.发布PHP项目

技术分享

技术分享

技术分享

丢弃旧的构建:保存10天的

 技术分享

找到GIT的项目URL(随便选的)

技术分享

技术分享

技术分享

进项目界面,再点击 deploy keys

技术分享

将那个KEY,enable一下

技术分享

1 #在另一台机器上创建一个放代码的目录
2 [root@linux-node1 ~]# mkdir -p /data/www/php-deploy

技术分享

点击立即构建

 1 #查看构建后的代码
 2 [root@linux-node2 php-deploy]# ll
 3 total 4
 4 -rw-r--r-- 1 root root 16 May 14 01:48 README.md
 5 #查看Jenkins拉代码的目录
 6 [root@linux-node2 php-deploy]# pwd
 7 /var/lib/jenkins/workspace/php-deploy
 8 #查看构建后是否同步成功
 9 [root@linux-node1 ~]# ll /data/www/php-deploy/
10 total 4
11 -rw-r--r-- 1 root root 16 May 14  2017 README.md

至此,PHP项目就已成功发布。

四.发布maven项目

技术分享

 

往gitlab上,上传一个maven项目:

 1 #进入项目目录
 2 [root@linux-node1 ~]# cd java2
 3 #初始化成git仓库
 4 [root@linux-node1 java2]# git init
 5 Initialized empty Git repository in /root/java2/.git/
 6 #添加
 7 [root@linux-node1 java2]# git add .
 8 #提交
 9 [root@linux-node1 java2]# git commit -m "first commit"
10 [master (root-commit) 3bad291] first commit
11  3 files changed, 100 insertions(+)
12  create mode 100644 pom.xml
13  create mode 100644 src/main/java/com/ghz/testweb/App.java
14  create mode 100644 src/test/java/com/ghz/testweb/AppTest.java
15 #远程仓库
16 [root@linux-node1 java2]# git remote add origin git@192.168.56.11:root/java-maven.git
17 #上传
18 [root@linux-node1 java2]# git push origin master

技术分享

 

 

 技术分享

技术分享

 1 #手动安装maven
 2 [root@linux-node2 ~]# tar xf apache-maven-3.3.9-bin.tar.gz 
 3 #放到/usr/local下
 4 [root@linux-node2 ~]# mv apache-maven-3.3.9 /usr/local/
 5 #设置环境变量
 6 [root@linux-node2 bin]# export PATH="$PATH:/usr/local/apache-maven-3.3.9/bin"
 7 #添加到环境变量文件
 8 [root@linux-node2 bin]# echo export PATH="$PATH:/usr/local/apache-maven-3.3.9/bin" >> /etc/profile
 9 #查看mvn版本
10 [root@linux-node2 bin]# mvn -v
11 Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
12 Maven home: /usr/local/apache-maven-3.3.9
13 Java version: 1.8.0_131, vendor: Oracle Corporation
14 Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/jre
15 Default locale: en_US, platform encoding: UTF-8
16 OS name: "linux", version: "3.10.0-327.36.3.el7.x86_64", arch: "amd64", family: "unix"
17 #修改镜像
18
[root@linux-node2 bin]# vim /usr/local/apache-maven-3.3.9/conf/settings.xml
  <?xml version="1.0" encoding="UTF-8"?>
  <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
   <mirror>
              <id>faxuan</id>
              <mirrorOf>*</mirrorOf>
              <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          </mirror>
      </mirrors>
          <profiles>
           <profile>
              <id>default</id>
              <repositories>
                  <repository>
                      <id>public</id>
                      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                      <releases>
                          <enabled>true</enabled>
                      </releases>
                      <snapshots>
                          <enabled>true</enabled>
                      </snapshots>
                  </repository>
              </repositories>
          </profile>
  </profiles>
      <activeProfiles>
          <activeProfile>default</activeProfile>
      </activeProfiles>
  </settings

技术分享

 

 技术分享

技术分享

 1 #查看构建结果
 2 [root@linux-node2 target]# pwd
 3 /var/lib/jenkins/workspace/java-maven/target
 4 [root@linux-node2 target]# ll
 5 total 8
 6 drwxr-xr-x 3 root root   16 May 14 04:36 classes
 7 drwxr-xr-x 2 root root   27 May 14 04:36 maven-archiver
 8 drwxr-xr-x 3 root root   34 May 14 04:36 maven-status
 9 -rw-r--r-- 1 root root 2431 May 14 04:36 original-testweb-v1.4.jar
10 drwxr-xr-x 2 root root   79 May 14 04:36 surefire-reports
11 drwxr-xr-x 3 root root   16 May 14 04:36 test-classes
12 -rw-r--r-- 1 root root 2658 May 14 04:36 testweb-v1.4.jar

 

 

 

【开源是一种精神,分享是一种美德】

  — By GoodCook

  — 笔者QQ:253097001

  — 欢迎大家随时来交流

  —原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。

【持续集成】GIT+jenkins+snoar——jenkins发布php、maven项目

标签:cache   jenkins   pat   read   status   文章   浏览器   first   size   

原文地址:http://www.cnblogs.com/goodcook/p/6856369.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!