1MVP
1.1MVP简介
MVP,Minimum Viable Product,借由这个概念来复习一下整个敏捷开发及部署的过程;
互联网产品要求小步快跑,快速迭代,想想一些大公司的代码每10秒变更一次,如果没有程序的自动一键部署该咋办;
1.2搭建测试环境
1.2.1在Linux环境下
Downloads>java -jar jenkins.war
1.2.2在Window环境下
下载并安装,填入初始密码,并安装建议的插件;设置好用户名和密码,就可以使用Jenkins了;
URL: http://localhost:8080/
1.2.3安装一些插件
Rebuilder
Safe Restart
1.2.4配置
Configure Global Security: Project-based Matrix Authorization Strategy - Add User or Group - admin
Manage User: Create User - contributor01
1.3环境准备
1.3.1虚拟机或VPS准备
IP地址:192.168.137.133,root/123456
安装JAVA: yum install java
安装Git: yum install git,并对Git进行初始化和生成授信证书
[root@localhost ~]# git config --global user.name "test"
[root@localhost ~]# git config --global user.email "test@gmail.com"
[root@localhost ~]# ssh-keygen -t rsa -C "test@gmail.com"
查看生成的证书,一个公钥,一个私钥
[root@localhost ~]# cd .ssh/
[root@localhost .ssh]# ls
id_rsa id_rsa.pub
1.3.2Git证书配置到github
验证
[root@localhost .ssh]# ssh git@github.com
1.4Maven
1.4.1安装Maven并安装
因为实际的项目是基于Maven构建的
http://maven.apache.org
[root@localhost ~]# wget http://www.trieuvan.com/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.zip
[root@localhost ~]# unzip apache-maven-3.5.4-bin.zip
1.4.2配置Maven
export MAVEN_HOME=/root/apache-maven-3.5.4
export PATH=$MAVEN_HOME/bin:$PATH
#加载配置文件
[root@localhost apache-maven-3.5.4]# . /etc/profile 或 source /etc/profile
[root@localhost apache-maven-3.5.4]# mvn -version
1.5Tomcat
1.5.1下载并解压
http://tomcat.apache.org
[root@localhost ~]# wget http://apache.spinellicreations.com/tomcat/tomcat-9/v9.0.11/bin/apache-tomcat-9.0.11.zip
[root@localhost ~]# unzip apache-tomcat-9.0.11.zip
1.5.2改变文件执行权限并启动
http://192.168.137.133:8080/
[root@localhost apache-tomcat-9.0.11]# chmod a+x -R *
[root@localhost apache-tomcat-9.0.11]# bin/startup.sh
1.6将Linux注册到Jenkins上
1.6.1创建新节点
Manage Jenkins - Manage Nodes - New Node
1.6.2连接
1.6.3创建一个新任务
1.6.4配置运行环境和添加脚本
1.6.5Build - Console Output查看输出
将Linux服务器作为远程节点注册到Jenkins,这样Jenkins就可以远程在服务器上执行任务
1.7Fork
1.7.1Fork获得源码
克隆到本地,需要本地安装Git,下载地址https://git-scm.com/download/win,并提供了git-bash
git@github.com:XXX/xxx.git
1.7.2导入存在的Maven工程到Eclipse
Run as maven install, 构建成功
本地安装Mysql并配置applicationContext.xml里的数据库信息,验证http://localhost:8071通过
1.7.3更新代码并提交
在项目的根目录下执行操作
$ git status //必须在项目的根目录
$ git add src/main/resources/spring/applicationContext.xml
$ git commit -m "update mysql configuration"
$ git push
1.8自动化部署
利用Jenkins将项目自动部署到测试环境
1.8.1Git同步最新代码到Jenkins
解决Jenkins无法访问Git的问题(这个步骤由网友提供,实际上不需要)
$ ssh-keygen -t rsa -C "XXX@gmail.com"
$ git.exe ls-remote -h git@github.com:XXX/order.git HEAD
Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.
配置本地的Jenkins账号(这个步骤由网友提供,实际上不需要)
1.8.2创建Jenkins部署任务
Description
Label Expression
Repositories
Additional Behaviours
Build
1.8.3遇到的错误
stderr: Host key verification failed.
ERROR: Error cloning remote repo 'origin'
#删除本地配置后出现如下错误:
ERROR: Workspace has a .git repository, but it appears to be corrupt.
Cannot run program "git.exe" (in directory "/root/.jenkins/workspace/MavenTask"): error=2, No such file or directory
'build.plugins.plugin.version' for org.apache.maven.plugins:maven-war-plugin is missing
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project order: Fatal error compiling: tools.jar not found
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
最后都在这里解决了:)