Jenkins部署Java项目配置

插件

插件: Publish Over SSH
插件: Maven Integration

创建任务

类型

选择构建一个Maven项目

凭据

添加凭据 -> Jenkins

Domain: 全局凭据
类型: Username with password

Pre Steps (可选)

选择执行 Shell

1
2
cd /root/.m2/repository/com/lianlian/global/pay
rm -rf *

Build

Root POM: appblog-registry/pom.xml
Goals and options: clean package -DskipTests -U

Post Steps

选择Send files or execute commands over SSHSend build artifacts over SSH

勾选Run regardless of build result

Name: 选择SSH发布配置的服务器
Source files: **/*.jar
Remove prefix: appblog-registry/target
Exec command:

1
2
3
4
5
6
7
project=appblog-registry
jar_name=`ls . | grep "$project"`
pid=`ps -ef | grep "$jar_name" | grep java | awk '{print $2}'`
if [ $pid ]; then
kill -9 $pid
fi
nohup /usr/local/java/jdk1.8.0_231/bin/java -jar -Dspring.profiles.active=prod $jar_name >/dev/null 2>&1 &

注:java务必使用全路径,否则登录SSH服务器的非root用户容易导致命令找不到

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :