下载
wget http://mirrors.jenkins.io/war-stable/2.164.3/jenkins.war
java -jar jenkins.war --httpPort=9999
nohup java -jar jenkins.war --httpPort=9999 &
#记录下admin用户的初始密码到本地文件,防止以后记不住
# 然后登录安装插件 Publish over SSH插件 创建管理员账号,配置jdk maven环境
本地配置
#Build
Root POM pom.xml
Goals and options clean install
#构建 执行shell
export BUILD_ID=dontkillme
echo 'stop.....'
/usr/local/tomcat-cow-manage/bin/catalina.sh stop
rm -rf /usr/local/tomcat-cow-manage/mywebapps/bulls.war
rm -rf /usr/local/tomcat-cow-manage/mywebapps/bulls/*
\cp -f /home/zyy/.jenkins/workspace/bulls-base/bulls-admin/target/bulls-admin.war /usr/local/tomcat-cow-manage/mywebapps/bulls.war
unzip -oq /usr/local/tomcat-cow-manage/mywebapps/bulls.war -d /usr/local/tomcat-cow-manage/mywebapps/bulls
sleep 5
/usr/local/tomcat-cow-manage/bin/catalina.sh start
echo 'start.....'
远程服务器配置
#Build
Root POM pom.xml
Goals and options clean package -Ptest
#Post Steps send file or exe commonds over ssh
#先在系统设置里设置Publish over SSH 添加SSH Servers 路径一般设置为/ 相对于用户的目录下
#SSH Publishers配置 copy的文件一定要在此项目目录下才可以
Name :选择一个要发布的应用服务器的ssh server用户
Transfers
Source files #本地的war包位置 eg: target/***.war
Remove prefix #去掉前面的路径 eg: target
Remote directory #指定要上传到应用服务器的位置 /home/user/
Exec command #在应用服务器上要执行的脚本文件 eg:/home/user/script/deploy.sh
#deploy.sh
#!/bin/sh
warName=`ls -t /home/user/wars/ | head -1`
echo $warName
\mv -f /home/user/wars/$warName /usr/local/tomcat8/webapps/app.war
chmod -777 /usr/local/tomcat8/app/app.war
---------
#!/bin/sh
export JAVA_HOME=/usr/lib/jvm/java/jdk1.8.0_191
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
echo 'start...'
warName=`ls -t /home/bulls/wars/ | head -1`
echo $warName
TOMCATTHREAD=`ps aux | grep 'bulls' | grep 'tomcat' | grep -v grep`
if test -z "$TOMCATTHREAD"
then
echo "TOMCAT NOT START"
else
THREADLIST=(${TOMCATTHREAD// / })
PID=${THREADLIST[1]}
kill -9 $PID
sleep 5s
fi
rm -rf /usr/local/tomcat/mywebapps/app.war
rm -rf /usr/local/tomcat/mywebapps/app/*
\cp -rf /home/bulls/wars/$warName /usr/local/tomcat/mywebapps/app.war
unzip -oq /usr/local/tomcat/mywebapps/app.war -d /usr/local/tomcat/mywebapps/app
sleep 5
/usr/local/tomcat/bin/catalina.sh start