问题如摘要描述;问题缘由分析参考 jenkins找不到环境变量java
解决方案:在须要执行的脚本前加上 /bin/bash -l 使当前登录用户以登录模式执行脚本文件nginx
案例:/bin/bash -l /opt/tomcat/tomcat1601/restart1601.shweb
restart1601.sh中的一个坑tomcat
启动tomcat须要先找到tomcat pid 杀掉进程再启动,刚开始写了一个脚本在本机执行能够,可是在jenkins中执行就直接失败了 缘由是杀进程的时候把grep本身也杀掉了,而后ssh断开链接bash
可用的脚本以下app
restart1601.shssh
#!/bin/bash #echo "stop tomcat1601..." rm -rf /opt/tomcat/tomcat1601/webapps/sinterface ps -ef|grep tomcat1601|grep "java"|awk '{print "kill -9 " $2}' |sh #echo "kill tomcat1601" /bin/bash /opt/tomcat/tomcat1601/bin/startup.sh #echo "start up tomcat1601..."
补充问题:webapp
当发布后 拷贝新的war包到tomcat/webapps下 重启tomcat以前须要将原来解压的项目文件夹删除,不然tomcat启动时不会从新解压新的war包rest