我已经将jenkins配置为删除了tomcat现有工作区,将现有构建复制到tomcat工作区,然后重启tomcat。我使用jenkins的execute shell。该脚本如下:
#!/bin/sh
version=1.0.0-BUILD-SNAPSHOT
build_no=${BUILD_NUMBER}
if [ $build_no ]
then
cd ~
TOMCAT_WEBAPPS=`locate apache-tomcat | grep apache-tomcat | grep webapps | head -n 1 | awk '{ print $1 }'`
rm $TOMCAT_WEBAPPS/app-api.war
rm -rf $TOMCAT_WEBAPPS/app-api/*
rmdir $TOMCAT_WEBAPPS/app-api/
wget http://jenkins/job/project/ws/api/build/api-$version-$build_no-bin.zip
unzip -j connectedcare-api-$version-$build_no-bin.zip
rm api-$version-$build_no-bin.zip
cp api-$version.war $TOMCAT_WEBAPPS/app-api.war
rm api-$version.war
else
echo "Please specify the jenkins build number as an argument: "$0" <build_number>"
exit
fi
echo "Restarting tomcat ..."
TOMCAT_PID=`ps -ef | grep tomcat | grep java | awk ' { print $2 } '`
if [ $TOMCAT_PID ]
then
echo "Tomcat is running with PID" $TOMCAT_PID
echo "Forced tomcat stop with PID" $TOMCAT_PID
kill -9 $TOMCAT_PID
echo "Tomcat was stoped"
fi
echo "Starting tomcat"
TOMCAT_STARTUP_FILE=`locate apache-tomcat | grep apache-tomcat | grep startup.sh | awk ' { print $1 } '`
$TOMCAT_STARTUP_FILE
TOMCAT_PID=`ps -ef | grep tomcat | grep java | awk ' { print $2 } '`
if [ $TOMCAT_PID ]
then
echo "Tomcat is running with PID" $TOMCAT_PID
else
echo "Failed to start tomcat."
fi
运行构建时,结果如下:
Restarting tomcat ...
Tomcat PID 10152
Tomcat is running with PID 10152
Forced tomcat stop with PID 10152
Tomcat was stoped
Starting tomcat
Tomcat started.
Tomcat is running with PID 14781
问题是当我看着linux机器时tomcat没有运行,日志中没有任何东西,所以我无法弄清楚我做错了什么。你能给我一些建议吗?
谢谢
答案 0 :(得分:2)
我设法为此找到了解决方案。 Jenkins操纵名为BUILD_ID的环境变量。因此,在重新启动tomcat之前,需要以下代码行。
导出BUILD_ID = dontKillMe