- 首先终端需要安装git和maven
- 然后配置git的ssh key
- 最后再配置脚本:
#!/bin/sh
git_path="https://github.com/kirosxx/starConch.git"
code_path="/usr/workspace/"
projectName="starConch"
projectName1="starConch-1.0.0"
env="master"
if [ ! -d ${code_path}${projectName} ];
then
echo ${projectName}"不存在,检出该项目"
cd $code_path
git clone "git@github.com:kirosxx/starConch.git"
else
echo ${projectName}"存在,更新代码"
cd ${code_path}${projectName}
git reset --hard
git pull
fi
echo "删除项目"
rm -rf "${code_path}${projectName}/target"
echo "maven 生成项目war包${projectName}"
cd ${code_path}${projectName}
mvn install -Dmaven.test.skip=true -Denv=$env -U
if [ $? -ne 0 ]; then
exit 1
fi
echo "关闭jar服务"
pidList=$(ps aux | grep $projectName1 | grep -v grep | awk '{print $2}')
for pid in $pidList
do
kill -9 $pid
echo 'kill pid '$pid
done
echo "复制打包好的jar包到code_path下面"
cd ${code_path}
rm -rf "${projectName1}.jar"
cp "${code_path}${projectName}/target/${projectName1}.jar" ${code_path}
echo "启动jar包"
nohup java -jar "${code_path}${projectName1}.jar" &