结构图:其中common为配置项、工具模块,没有main方法;service_paper为核心业务模块
项目的打包类型:pom、jar、war
即:
<packaging>pom</packaging>
<packaging>jar</packaging>
<packaging>jar</packaging>
根据maven的继承特性,在service文件夹模块中添加:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
然后只需在每个有mian方法的具体的业务模块的pom中添加:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
最终打包:只需在最顶层模块的文件夹进行mvn clean package,生成jar包。
BUILD SUCCESS,jar包大小:67.8MB
此时的jar包可以直接运行了
#java environment
export JAVA_HOME=/export/servers/jdk
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
#maven environment
export MAVEN_HOME=/export/servers/apache-maven-3.8.1
export PATH=$PATH:$MAVEN_HOME/bin
yum -y install git
安装必要的一些系统工具
? yum install -y yum-utils device-mapper-persistent-data lvm2
添加软件源信息
? yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新并安装Docker-CE
? yum makecache fast
? yum -y install docker-ce
开启Docker服务
? service docker start
测试是否安装成功
? docker -v
nohup java -jar /export/servers/jenkins/jenkins.war >/export/servers/jenkins/jenkins.out &
访问jenkins
vi /root/.jenkins/secrets/initialAdminPassword
2a447e76c0e940afb256d0779d972654
输入密码后,继续
官方下载插件慢,需要更新下载地址
注:这里要先先杀死Jenkins
kill -9 10967
进入更新配置位置:cd {你的Jenkins工作目录}/updates
cd /root/.jenkins/updates
sed -i ‘s/http://updates.jenkins-ci.org/download/https://mirrors.tuna.tsinghua.edu.cn/jenkins/g‘ default.json && sed -i ‘s/http://www.google.com/https://www.baidu.com/g‘ default.json
(注:这里是直接修改配置文件,如果前边Jenkins用sudo启动的话,那么这里的两个sed前均需要加上sudo)
重试
插件安装完成,创建管理员用户
保存并完成
使用which命令
which jdk
/export/servers/jdk
which maven
/export/servers/apache-maven-3.8.1
which git
/usr/bin/git
#!/bin/bash
#maven打包
mvn clean package
echo ‘package ok!‘
echo ‘build start!‘
cd ./
service_name="service-paper"
service_prot=8001
#查看镜像id
IID=$(docker images | grep "$service_name" | awk ‘{print $3}‘)
echo "IID $IID"
if [ -n "$IID" ]
then
echo "exist $SERVER_NAME image,IID=$IID"
#删除镜像
docker rmi -f $service_name
echo "delete $SERVER_NAME image"
#构建
docker build -t $service_name .
echo "build $SERVER_NAME image"
else
echo "no exist $SERVER_NAME image,build docker"
#构建
docker build -t $service_name .
echo "build $SERVER_NAME image"
fi
#查看容器id
CID=$(docker ps | grep "$SERVER_NAME" | awk ‘{print $1}‘)
echo "CID $CID"
if [ -n "$CID" ]
then
echo "exist $SERVER_NAME container,CID=$CID"
#停止
docker stop $service_name
#删除容器
docker rm $service_name
else
echo "no exist $SERVER_NAME container"
fi
#启动
docker run -d --name $service_name --net=host -p $service_prot:$service_prot $service_name
#查看启动日志
#docker logs -f $service_name
回到首页面
service docker start
下载依赖中
构建
后台查看运行情况,没问题
使用Jenkins测试CI/CD的自动、持续构建及测试软件(在虚拟机中)
原文:https://www.cnblogs.com/211806342wbw/p/15112841.html