一:安裝tomcat、jdk
略
二:下載Jenkins含鳞、maven
[root@localhost ~]# wget http://mirrors.jenkins-ci.org/war/2.25/jenkins.war
[root@localhost ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
三:安裝maven
#解壓apache-maven-3.3.9-bin.tar.gz
[root@localhost ~]# tar zxvf apache-maven-3.3.9-bin.tar.gz -C /usr/local/
[root@localhost ~]# ln -s apache-maven-3.3.9/ maven
[root@localhost ~]# vim /etc/profile
......
export MAVEN_HOME=/usr/local/maven
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
四:安裝Jenkins
#將jenkins.war放入tomcat webapps目錄下啟動(dòng)tomcat:
[root@localhost ~]# cp jenkins.war /usr/local/tomcat/webapps/
[root@localhost ~]# sh /usr/local/tomcat/bin/startup.sh
五:打開(kāi)瀏覽器配置
- 安裝插件,這里選擇默認(rèn)安裝
完成后添加必須的插件
系統(tǒng)管理 -> 插件管理 -> 可選插件
Maven Integration plugin,Publish Over SSH,SVN Publisher plugin (如果安裝失敗,重啟tomcat重新安裝)
- 插件安裝完成后開(kāi)始設(shè)置常用配置
配置發(fā)送war包到遠(yuǎn)程的主機(jī)(系統(tǒng)管理->系統(tǒng)設(shè)置)
如果新建任務(wù)中沒(méi)有創(chuàng)建maven任務(wù)癌蓖,需配置maven插件(系統(tǒng)管理->Global Tool Configuration)
- 開(kāi)始配置任務(wù)
六:構(gòu)建后遠(yuǎn)程主機(jī)腳本:
[root@localhost ~]# cat tomcat.sh
#/bin/bash
export JAVA_HOME=/usr/local/java
sh /usr/local/tomcat/bin/shutdown.sh
#將war包復(fù)制到網(wǎng)站跟目錄
cp /opt/tomcat_war/target/shortUrl.war /usr/local/tomcat/webapps/
#遍歷根目錄下war文件怯晕,如果有該文件哟旗,則將同名的目錄移動(dòng)到/opt/tomcat_back/下
for f in $(find /usr/local/tomcat/webapps/ -name "*.war")
do
war_file=$(basename $f)
pro_name=${f%.war}
mv $pro_name /opt/tomcat_back/$(date +%Y%m%d%H%M)_$war_file
done
sh /usr/local/tomcat/bin/startup.sh && tail -f /usr/local/tomcat/logs/catalina.out