码迷,mamicode.com
首页 > 其他好文 > 详细

Jenkins 自动化部署sh参考

时间:2021-02-25 12:21:35      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:cti   snap   root   修改文件   pid   包名   files   自动化部署   echo   

!/bin/bash -ilex

服务名称

SERVER_NAME=project-name

源jar路径,mvn打包完成之后,target目录下的jar包名称,也可选择成为war包,war包可移动到Tomcat的webapps目录下运行,这里使用jar包,用java -jar 命令执行

JAR_NAME=project-name-0.0.1-SNAPSHOT

源jar路径

/usr/local/jenkins_home/workspace--->jenkins 工作目录

demo 项目目录

target

Jenkins 自动化部署sh参考:
打包生成jar包的目录
JAR_PATH=/var/lib/jenkins/workspace/otc-ud/target

打包完成之后,把jar包移动到运行jar包的目录--->work_daemon,work_daemon这个目录需要自己提前创建

JAR_WORK_PATH=/usr/soft/jm

复制jar包到执行目录

echo "复制jar包到执行目录:cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH"
cp $JAR_PATH/$JAR_NAME.jar $JAR_WORK_PATH
echo "复制jar包完成"
cd $JAR_WORK_PATH

修改文件权限

chmod 755 $JAR_NAME.jar
ssh -tt root@43.249.193.149 -p 15777 << remotessh
cd /usr/local/application/new-path
mv project-name-0.0.1-SNAPSHOT.jar "project-name-0.0.1-SNAPSHOT-"date +%Y%m%d%H%M%S".jar"
exit
remotessh
scp -P 15777 /usr/soft/jm/project-name-0.0.1-SNAPSHOT.jar root@43.249.193.149:/usr/local/application/new-path/

sshpass -p "sk8daXQ9MJOUCewp" ssh root@43.249.193.149 -p 15777 ‘sh /usr/local/application/new-path/sh/project-name.sh‘

/usr/bin/sshpass -p sk8daXQ9MJOUCewp ssh root@43.249.193.149 -p 15777 ‘sh /usr/local/application/new-path/sh/project-name.sh‘

/usr/local/application/new-path/sh/project-name.sh:

!/bin/bash

SERVER_NAME=project-name
JAR_NAME=project-name-0.0.1-SNAPSHOT

echo "查询进程id-->$SERVER_NAME"
PID=ps -ef | grep "$SERVER_NAME" |grep -v grep | awk ‘{print $2}‘
echo "得到进程ID:$PID"
echo "结束进程"
for id in $PID
do
kill -9 $id || true
echo "killed $id"
done
echo "结束进程完成"

cd /usr/local/application/project-name/

echo "进来/usr/local/application/project-name/"

nohup /usr/local/java/jdk1.8.0_131/bin/java -jar /usr/local/application/new-path/project-name-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod149 &
echo "执行完毕"

Jenkins 自动化部署sh参考

标签:cti   snap   root   修改文件   pid   包名   files   自动化部署   echo   

原文地址:https://www.cnblogs.com/LoveShare/p/14445459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!