jenkins部署git前端项目
1.前端项目不需要mvn,所以建一个自由的项目即可
前端
#!/bin/sh
#打包目录,需手动创建
TARGET_BASE_FOLD=ms-admin #打包机前端代码打包名称 FILENAME=dist #打包机打包的包路径 BASE=/root/.jenkins/workspace/ms-admin #部署机包目录 TARGET_WAR_FOLD=~/service/${TARGET_BASE_FOLD} #拉前端代码,执行打包命令 cd ${BASE} npm i npm run build:prod #压缩包 zip -q -r ${FILENAME}.zip ${FILENAME} #进入部署机,jenkins与部署机不是一台 SSH="sshpass -p $PASSWD ssh -o StrictHostKeyChecking=no" for ip in $IPLIST do echo "ip:"$ip" start" $SSH root@$ip "source /etc/profile && cd $TARGET_WAR_FOLD && rm -rf $TARGET_WAR_FOLD/$FILENAME* 2>&1 &" sshpass -p $PASSWD scp -P 22 $BASE/$FILENAME.zip root@$ip:$TARGET_WAR_FOLD $SSH root@$ip "source /etc/profile && cd $TARGET_WAR_FOLD && unzip $FILENAME.zip 2>&1 &" echo "ip:"$ip" done" done
后端
#!/bin/sh
JenkinsWorkspace=$JENKINS_HOME/workspace/ms-parent/ms-admin-api/target/ms-admin-api.jar
Workspace=~/service/ms-parent/webapps
SSH="sshpass -p $PASSWD ssh -o StrictHostKeyChecking=no"
for ip in $IPLIST
do
echo "ip:"$ip" start"
$SSH root@$ip "source /etc/profile && cd ~/service/ms-parent/webapps && ./shutdown.sh && rm -rf ./*.jar 2>&1 &"
sshpass -p $PASSWD scp -P 22 $JenkinsWorkspace root@$ip:$Workspace
$SSH root@$ip "source /etc/profile && cd ~/service/ms-parent/webapps && ./start.sh 2>&1 & "
echo "ip:"$ip" done"
done
start.sh:
java -jar ms-admin-api.jar --server.port=9002 --spring.profiles.active=dev > /export/Logs/ms-parent/logs.txt 2>&1 &
shutdown.sh
ps -aef | grep "9002"| grep -v grep | sed 's/ [ ]*/:/g' |cut -d: -f2 |kill -9 `cat`
2.安装nginx,https://www.cnblogs.com/Alysa-lrr/p/13857006.html