添加ssh插件
连接远程的服务器
部署前后端分离的项目
- 部署后端
stop.sh
# 将应用停止
#stop.sh
#!/bin/bash
echo "Stopping SpringBoot Application"
pid=`ps -ef | grep school-sportmeeting-system-0.0.1-SNAPSHOT.jar | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
kill -9 $pid
fi
#此处school-sportmeeting-system-0.0.1-SNAPSHOT.jar根据自己的jar包名称修改
deployJar.sh
#deployJar.sh 用于部署Java服务
#!/bin/bash
nohup java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=2222 /www/server/schoolMeetingJenkins/target/school-sportmeeting-s
ystem-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod > school-sportmeeting-system.log 2>&1 &
坑点:Jenkins默认的java执行路径是/usr/bin/java,所以远程服务器的java路径需要添加一个软连接
ln -s $JAVA_HOME/bin/java /usr/bin/java
否则会报错:nohup: failed to run command `java': No such file or directory
- 部署前端
deploy.sh
#deploy.sh 用于部署前端项目
#!/bin/bash
cd /www/server/schoolMeetingJenkins/vue/sportmeeting-vue
cp -rf dist/ /www/server/nginx/html/ #复制文件夹覆盖到nginx的静态文件夹
- 因为是maven的Jenkins项目,所以在maven打包前,我们需将前端打包下,所以需添加如下配置
取消之前的配置的Post Steps
最后点击保存,点击构建!