Deploy the spring cloud project using jenkins

先简单记录下Jenkins部署maven聚合工程要点!

Bulid配置

http://cdn.telami.cn/knowledge/20191030214545-fcTyhB.png

重点就在下面👇

1
clean install -pl stark-uaa -am -amd -Dmaven.test.skip=true

Root pom配置成项目根目录的pom.xml

maven命令单独install 欲构建的项目

  • -pl:–projects Build specified reactor projects instead of all projects 选项后可跟随{groupId}:{artifactId}或者所选模块的相对路径(多个模块以逗号分隔)

  • -am:–also-make If project list is specified, also build projects required by the list 表示同时处理选定模块所依赖的模块

  • -amd:–also-make-dependents If project list is specified, also build projects that depend on projects on the list 表示同时处理依赖选定模块的模块

  • -N:–Non-recursive Build projects without recursive 表示不递归子模块

  • -rf:–resume-from Resume reactor from specified project 表示从指定模块开始继续处理

Shell 脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash -ile
project=stark-uaa-1.0.0.jar
pathName=uaa
echo "copy file"
rm -rf /opt/stark/$project
cp  /var/lib/jenkins/workspace/$pathName/stark-uaa/target/$project /opt/stark/
echo "switch path"
cd /opt/stark/
 
pid=`ps -ef | grep $dir$project | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
   kill -9 $pid
   echo "kill exist process"
fi
BUILD_ID=dontKillMe 
echo "running"
nohup java -jar $project &
echo "start successfully!"

都是趟过的坑啊。