1、项目代码上传SVN服务器,这里以 SpringBoot 的 HelloWolrd 入门为例;
2)启动 Jenkins ,访问首页,点击 “新建任务” 进入如下界面:

3)配置项目相关信息

4)配置 SVN 信息


5)配置触发器

6)配置构建信息

7)配置 Post Steps

#!/bin/bash
cd /usr/local/scripts
echo "Execute shell Start"
sh stop.sh "hello-1.0-SNAPSHOT.jar"
sh replace.sh "hello-1.0-SNAPSHOT.jar"
chmod 777 /usr/local/scripts/startup.sh
BUILD_ID=dontKillMe
sh startup.sh "hello-1.0-SNAPSHOT.jar"
echo "Execute shell Finish"
-------- stop.sh --------
#!stop.sh
#!/bin/bash
cd /usr/local/scripts
echo "Stopping SpringBoot Application..."
ls
pid=`ps -ef|grep $1 | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
#!kill -9 强制终止
echo "kill -9 的pid:" $pid
kill -9 $pid
fi
-------- replace.sh --------
#!replace.sh
#!/bin/bash
#!判断jar是否存在,存在将现有的jar备份后,将新的jar包替换
file="/workspace/$1"
if [ -f "$file" ]
then
cp '$file' /workspace/backup/`date+%Y%m%d%H%M%S`-'$1'
fi
cp /root/.jenkins/workspace/target/'$1' /workspace
-------- startup.sh --------
#!startup.sh
#!/bin/bash
ehco "授予当前用户权限"
chmod 777 /workspace/$1
echo "执行....."
cd /workspace
java -jar $1 &
8)保存配置信息,跳转至 项目主界面,点击“立即构建” ,如下图:

至此完成项目自动化部署的初次实现工作。
网友评论