#!/bin/sh
#项目的git地址
git_path="服务器地址:端口/xxx/xxx.git"
#本地代码位置代码路径
code_path="/Users/xxxx/Documents/bushu-home/"
#项目名称
projectName="xxx"
projectName3="xxx-admin"
projectName4="xxx-protal"
ip2=Ip
gitIp=IP
env="pangoo"
#git账号密码
username=xxx
password=xxx
#如果项目文件夹不存在说明没有下载过改项目代码,需要检出该项目
if [ ! -d ${code_path}${projectName} ];
then
echo ${projectName}"不存在,检出该项目"
cd $code_path
git clone -b pangoo "http://${gitIp}:9099/xxx/xxx.git"
# git clone -b pangoo "http://${username}%:${password}@${gitIp}:9099/xxx/xxx.git"
else
echo ${projectName}"存在,更新代码"
cd ${code_path}${projectName}
git reset --hard
git pull
fi
# 删除项目
echo "删除项目"
rm -rf "${code_path}${projectName}/${projectName3}/target"
echo "maven 生成项目war包${projectName}"
cd ${code_path}${projectName}
mvn clean install -Dmaven.test.skip=true
#如果打包出错直接退出
if [ $? -ne 0 ]; then
exit 1
fi
echo "将本地文件上传到服务器"
sshpass -p 服务器密码xxx scp -P 8122 -r ${code_path}${projectName}/${projectName3}/target/xxx-admin.jar root@${ip2}:/usr/local/xxx/xxx/
echo "启动项目中 ...."
plink -P 端口 -batch -pw 服务器密码xxx root@${ip2} "source /etc/profile; source /root/.bash_profile; cd /usr/local/xxx/xxx; sh start.sh"
echo Start test home-admin Success!
第一步:在git拉取代码;如果有则更新代码
第二步:编译打包项目生成jar包
第三步:上传jar到服务器
第四步:启动项目
mac :一、需要下载plink
二、需要下载sshpass
坑:首次用命令链接服务器会有一个报错:
The host key is not cached for this server:
ip (port 22)
You have no guarantee that the server is the computer you
think it is.
The server's ssh-ed25519 key fingerprint is:
ssh-ed25519 255 SHA256:Kgs8rpt/93G1mFSSLlXySmhjNKGrqckcv4qWTih0VW0
Connection abandoned.
FATAL ERROR: Cannot confirm a host key in batch mode
Start test home-admin Success!
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
解决:
ssh 服务器ip -P 服务器端口
然后输入密码
忘了,面的代码是sh文件,还需要创建一个mac可执行文件test.command
cd /Users/xxx/Desktop/
sh testStart.sh
然后给此文件一个可执行权限
chmod +x test.command
最后一键test.command。 搞定!