一、从git上拉取代码,打包发布
1、springboot 项目 maven配置如下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.5</version>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
2、jenkins配置:
1)、创建一个 maven项目 任务
如果没有此选项,需要下载插件,此过程略。
2)、general 和 源码 配置
3)、构建触发器 配置
4)、
5)、
PIDS=`ps -ef | grep "voice-0.0.1-SNAPSHOT.jar" | grep -v "grep" | awk '{print $2}'`
if [ "$PIDS" != "" ]; then
sudo kill -9 "$PIDS"
echo "已关闭服务!"
else
echo "不存在,不执行关闭"
fi
mv /var/lib/jenkins/workspace/kylin-voice-dev/target/voice-0.0.1-SNAPSHOT.jar /opt/workspace/kylin/dev
BUILD_ID=dontKillMe nohup java -Dfile.encoding=utf-8 -jar /opt/workspace/kylin/dev/voice-0.0.1-SNAPSHOT.jar > /opt/workspace/kylin/dev/wisdom-case/ws-voice-logs/voice.out 2>&1 &
二、从git上拉取代码打包后把jar复制到另外服务器上进行运行
1、springboot 项目 maven配置 同上
2、jenkins配置:
1)- 3) 步骤同上
4)、
5)、
6)、其它说明 5)中 ssh server的配置如下
6)、其它说明 5)是在另外的远程服务器上运行,且是以linux系统服务的方式启动
设置服务启动方式步骤:
1、在/etc/systemd/system下创建一个相应的xxxx.service文件
sudo ln -s
/data/workspace/ste-cloud/dingtalk/ste-dingtalk.service /etc/systemd/system/ste-dingtalk.service
注:因为权限原因,先创建再复制到/etc/systemd/system下
2、systemctl enable xxxx.service设置为开机启动(非必须,一般不设置)
3、systemctl daemon-reload,重新加载配置文件(必须)
sudo systemctl daemon-reload
4、启动服务,systemctl start xxxx,这里的xxxx代表的是service文件的名,或者是systemctl start xxxx.service ;(重启: systemctl restart xxxx.service)
5、停止服务,systemctl stop xxxx,这里的xxxx代表的是service文件的名,或者是systemctl stop xxxx.service
6、查看服务状态,systemctl status xxxx
xxxx.service 文件内容:为启动jar的命令
[Unit]
Description=KylinCase Basic Product Server
[Unit]
Description=KylinCase Basic Product Server
After=nacos.target
[Service]
Environment=NACOS_HOST=127.0.0.1:8848
Environment=NACOS_NAMESPACE=mynacos-namespace
ExecStart=/usr/local/jdk/bin/java -Xmx1024m -Dfile.encoding=utf-8 -Duser.timezone=GMT+8 -jar /data/workspace/kylincase/transaction/xxx-0.0.1-SNAPSHOT.jar
[Install]
WantedBy=multi-user.target