jenkins使用maven打包发布到远程服务器

下载jenkins https://jenkins.io/download/

nohup java -jar jenkins.war &

使用http://127.0.0.1:8080访问jenkins 首次登陆需要设置用户名密码 下载插件

1.安装Publish Over SSH插件; 
2.安装Maven Integration plugin插件(目的是创建maven构建项目,如下图); 
这里写图片描述
3.安装git插件; 
4.登录jenkins-系统管理-系统设置-Publish Over SSH,配置远程服务器; 
这里写图片描述
5.新构建一个maven项目,配置git仓库地址,最重要的配置是将文件传送到远程服务器配置 
这里写图片描述

说明:
Source files的目录是基于当前job的目录(可以从jenkins的安装目录下找到):例如当前job名称为people-info-server,则对于root用户,Source files中的目录是相对于/var/jenkins_home/workspace/people-info-server目录下的,因此,如果我们要发送people-info-server下的xx项目的jar包,这里需要填写:xx/target/xx-0.0.1.SNAPSHOT.jar
Remove prefix:表示需要移除的目录,比如这里填写xx/target,则表示发布时,只把xx-0.0.1.SNAPSHOT.jar发布到远程linux,而不包含xx/target目录结构
Remote directory:表示需要把编译好的war包发布到远程linux的哪个目录下
Exec command:需要执行的shell命令,shell命令在远程linux服务器上.

注意: 
job名称不能和项目名称相同,否则上传不了 
这里写图片描述

echo "hello xx-0.0.1.SNAPSHOT.jar"  DAY=`date +%Y-%m-%d`  pid=`ps -ef|xx|grep -v grep|awk '{print $2}'`  if [ -n "$pid" ] then echo 'The pid: server' $pid ' will be killed....' kill -9 $pid echo 'The pid: server' $pid ' will be start' nohup java -jar /data/jekins/xx/xx-0.0.1.SNAPSHOT.jar >  /dev/null &  else echo 'The pid: server' $pid ' not exist , will be start' nohup java -jar /data/jekins/xx/xx-0.0.1.SNAPSHOT.jar >  /dev/null & fi echo 'The pid: server' $pid ' started'

附上shell脚本(Post Steps–SSH Publishers–Transfers–Exec command):
echo "hello xx-0.0.1.SNAPSHOT.jar"

DAY=`date +%Y-%m-%d`

pid=`ps -ef|xx|grep -v grep|awk '{print $2}'`

if [ -n "$pid" ]
then
echo 'The pid: server' $pid ' will be killed....'
kill -9 $pid
echo 'The pid: server' $pid ' will be start'
nohup java -jar /data/jekins/xx/xx-0.0.1.SNAPSHOT.jar >  /dev/null & 
else
echo 'The pid: server' $pid ' not exist , will be start'
nohup java -jar /data/jekins/xx/xx-0.0.1.SNAPSHOT.jar >  /dev/null &
fi
echo 'The pid: server' $pid ' started'

猜你喜欢

转载自blog.csdn.net/luckykapok918/article/details/80838935