jenkins发布项目

一、从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设置为开机启动(非必须,一般不设置)

3systemctl 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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值