Jenkins Maven Tomcat 持续集成配置教程
前言
Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。 [ 百度百科 ]
开始
1 .先安装java环境,配置好环境变量等操作
yum -y install java-1.8.0-openjdk.x86_64
vi /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
source /etc/profile
java -version
2 .下载Jenkins,并安装
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum -y install jenkins
chkconfig jenkins on --开机启动
service jenkins restart
3 .打开网页输入地址即可访问jenkins,注意关闭防火墙,查看账号(admin/27dd1ac3461942e5a76708d0f13709f7) , http://192.168.199.68:8080/
vi /var/lib/jenkins/secrets/initialAdminPassword
4 .安装部分插件 主页->系统管理->管理插件->可选插件
Email Extension Plugin (邮件通知)
Deploy to container Plugin (部署到Java容器中的插件,必装)
Publish Over SSH (远程Shell)
Maven Integration plugin (Maven集成,否则新建的时候没有Maven Project,必装)
Monitoring (监控Jenkins所消耗的系统资源,如内存使用等)
Git plugin (Git插件,必装)
5 .安装mvn (/usr/share/maven) ,修改仓库镜像,如有是自定义镜像库,自行修改
yum install maven
mvn -version
vi /usr/share/maven/conf/settings.xml
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
6 .安装git,( /usr/bin/git )
yum install git
git --version
7 .安装Tomcat,修改端口为888,教程地址,并设置权限,访问地址:http://192.168.199.68:888/manager
vi /usr/local/tomcat/apache-tomcat-9.0.4/conf/tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="alvis" password="cxz222cxz" roles="manager-gui,manager-script"/>
vi /usr/local/tomcat/apache-tomcat-9.0.4/webapps/manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
</Context>
8 .下载jdk,( /usr/local/jdk/jdk1.8.0_161 )
mkdir -p /usr/local/jdk
tar -zxvf jdk-8u161-linux-x64.tar.gz -C /usr/local/jdk
9 .准备工作完毕,开始使用jenkins,系统管理->全局工具配置->jdk、maven取消自动安装,并写入自己的路径
git
/usr/bin/git
jdk
/usr/local/jdk/jdk1.8.0_161
maven
/usr/share/maven
10 .新建->构建一个maven项目,配置任务
Git->Repositories : http://192.168.199.66/third/test.git
add->username、password ( root / cxz222cxz )
Build->Goals and options : -P prod -e -B -Dmaven.test.skip=true clean install
构建后操作->Deploy war/ear to a container->
WAR/EAR files : **/*.war
Context path : test
Containers : TomCat 8 X
Credentials : username / pwd ( alvis / cxz222cxz )
URL : http://192.168.199.68:888
Deploy on failure : OK
11 .开始执行,执行完后访问http://192.168.199.68:888/test/ 地址,查看自动部署的网站
结束
附上成功图片: