jenkins部署jar

Generally three servers are required. The
first server installs gogs,
installs gogs (git client), and submits springboot code. The
second server installs jenkins and
installs jdk (jenkins is written in java and depends on jdk)

Install maven (for packaging), modify the warehouse location in setting.xml, and add the Alibaba Cloud download address. It is best to upload the local warehouse to the server to save the time of downloading dependencies

Install jenkins, the plug-in needs to install the maven plug-in in addition to the default installation

Global configuration: configure jdk and maven, git uses the default (jenkins installs the git plugin by default)

jenkins new item
new maven project
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

The
content of the startup script start.sh is as follows:

#!/bin/sh
#Copy jar to target path

BUILD_ID=DONTKILLME #后台执行

pid=$(ps -ef|grep demo-0.0.1-SNAPSHOT.jar|grep -v grep | awk '{print $2}')

#copy jar 到启动目录  /var/lib/jenkins/workspace/为jenkins的工作目录,springboot-test为jenkins新建的item的name
cp -r /var/lib/jenkins/workspace/springboot-test/target/demo-0.0.1-SNAPSHOT.jar  /home/jar/demo

# 关闭已经启动的jar进程
function stop(){
    
    
if [ -n "$pid" ]
  then
        echo "pid进程 :$pid"
        kill -9 $pid
    
 else
    echo "进程没有启动"
fi
}
stop

sleep 5s

#发布jar服务
function start(){
    
    
  cd /home/jar/demo
  nohup java -jar demo-0.0.1-SNAPSHOT.jar --server.port=8082 >demo.log 2>&1 &
}

start

Need to create a new file /home/sh/start.sh (script)
create a new directory /home/jar/demo (the location of the jar package copy)

Insufficient authority problem
vim /etc/sysconfig/jenkins
modify JENKINS_USER="jenkins" to JENKINS_USER="root"

I only use two servers (Jenkins and jar are on the same server). If you use three servers, the third server is used to store the jar package, and you need to configure ssh globally in jenkins
(refer to the pdf file for details)

Guess you like

Origin blog.csdn.net/weixin_44892460/article/details/110673429