Jekins+maven+git+docker
1. 确认jekins JDK的版本
2. 确认git拉取地址
3. 参考:https://blog.csdn.net/qq_35904833/article/details/78813638
4. https://blog.csdn.net/shichen2010/article/details/78331836
5. shell脚本:https://blog.csdn.net/njzcx/article/details/80979157
6. jekins安装:
https://www.cnblogs.com/grey-wolf/p/8716662.html
https://blog.csdn.net/u013257425/article/details/53493113 / http://mirrors.jenkins-ci.org/war/
构建自由风格:https://blog.csdn.net/qq_35620501/article/details/88600669
7. 插件安装失败:https://www.cnblogs.com/kaola8023/p/7082192.html
https://mirrors.tuna.tsinghua.edu.cn/jenkins/
tomcat 6下部署jenkins.war,访问报404,后台日志错误:
java.net.UnknownHostException: bogon: bogon: Name or service not known
host文件配置:127.0.0.1 bogon
安装后的工作目录:cd /root/.jenkins/workspace
配置maven项目编译,maven 执行的命令:
https://cloud.tencent.com/developer/article/1371238
Ⅳ、项目构建成功后部署应用服务器的配置
“增加构建后的操作步骤”-->“Send build artifacts over SSH”:
执行脚本:
#针对 项目 放到 /home下,且指向/home/auto-deploy.sh脚本
#tomcat 路径
TOMCAT_HOME=/home/tomcat8
#tomcat 端口
TOMCAT_PORT=8080
#java项目名,不用写.war
PROJECT_NAME=im-server-1.0.0
check_port() {
echo "正在检测Tomcat端口:"$1
netstat -tlpn | grep "\b$1\b"
}
if check_port $TOMCAT_PORT
then
echo $TOMCAT_PORT"端口存在,开始杀死对应PID"
kill -9 `ps -ef | grep tomcat | awk 'NR==1 {print $2}'`
else
echo $TOMCAT_PORT"端口空闲"
fi
echo "强制删除tomcat下的项目"$TOMCAT_HOME"/webapps/"$PROJECT_NAME
rm -rf $TOMCAT_HOME"/webapps/"$PROJECT_NAME
echo "强制删除tomcat下的项目"$TOMCAT_HOME"/webapps/"$PROJECT_NAME".war"
rm -rf $TOMCAT_HOME"/webapps/"$PROJECT_NAME".war"
echo '删除完成'
cd $TOMCAT_HOME"/webapps"
echo "查看当前"$TOMCAT_HOME"/webapps目录下的文件"
ls -a
echo "将远程打包的war包放入到"$TOMCAT_HOME"/webapps/下"
mv /home/$PROJECT_NAME".war" $TOMCAT_HOME/webapps
cd $TOMCAT_HOME/bin
./startup.sh
DATE_N=`date "+%Y-%m-%d %H:%M:%S"`
echo $PROJECT_NAME" 最新构建部署时间:${DATE_N}" >> ../../check_port.log #记录启动日志
echo "####################"$PROJECT_NAME"启动成功####################"
1. jenkins自动部署脚本样例:https://www.cnblogs.com/xxj0316/p/9467182.html
先测试宿主机(下面的脚本不需要写在.sh文件里):
#!/bin/sh
#kill tomcat pid
#这句尤为重要
export BUILD_ID=tomcat_mobile_build_id
# 1.关闭tomcat
pidlist=`ps -ef|grep tomcat_mobile|grep -v "grep"|awk '{print $2}'`
function stop(){
if [ "$pidlist" == "" ]
then
echo "----tomcat 已经关闭----"
else
echo "tomcat进程号 :$pidlist"
kill -9 $pidlist
echo "KILL $pidlist:"
fi
}
stop
pidlist2=`ps -ef|grep tomcat_mobile|grep -v "grep"|awk '{print $2}'`
if [ "$pidlist2" == "" ]
then
echo "----关闭tomcat成功----"
else
echo "----关闭tomcat失败----"
fi
# 2.移除原来tomcat中webapps中的项目文件夹
rm -rf /usr/local/tomcat_mobile/webapps/uum*
# 3.复制jenkins生成的war包到tomcat中webapps中
cp -r /var/lib/jenkins/workspace/baiyangjinrong-mobile/mobile/target/mobile.war /usr/local/tomcat_mobile/webapps
sleep 3s
# 4.修改war包的名称
mv /usr/local/tomcat_mobile/webapps/mobile.war /usr/local/tomcat_mobile/webapps/ROOT.war
# 5.启动tomcat
cd /usr/local/tomcat_mobile/bin
./startup.sh
远程tomcat: