1,新建一个job
2,配置git下载地址
3,配置build后执行的脚本
4,脚本执行过程会报没有权限,因为jenkins默认用户是jenkins,改成root
vi /etc/sysconfig/jenkins
5,脚本如下:
echo "脚本开始执行"
path=$1
cd $path
filename=$(ls *jar)
echo $filename
echo "杀死原来的进程开始"
pid=`ps -ef | grep $filename | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
echo "kill -9 的pid:" $pid
kill -9 $pid
fi
echo "杀死原来的进程结束"
echo "替换jar包开始"
file="/usr/local/code/jenkinsjar/"$filename
if [ -f "$file" ]
then
rm -f /usr/local/code/jenkinsjar/$filename
rm -f /usr/local/code/jenkinsjar/$filename.log
fi
cp $path/$filename /usr/local/code/jenkinsjar/
echo "替换jar包结束"
echo "执行jar开始"
cd /usr/local/code/jenkinsjar
nohup java -jar $filename > $filename.log &
echo "执行jar结束"
echo "脚本执行完毕"