This is the first day of my participation in the Gwen Challenge in November. Check out the details: the last Gwen Challenge in 2021

In a development environment, versioning deployment is very troublesome, so persistent integration can greatly reduce the workload of operation and maintenance. This article will explain how to continuously deploy the SpringBoot project.

1. Principles of Jenkens sustainable deployment

The principle of sustainable deployment is simple: download the code from your SVN/Git, and then get the package of the configuration and put it into a JAR package. Then use SSH to connect to the server where you want to publish and execute the startup syntax you provided.

2. Install

2. Install the JDK

3. Install maven

4. Configure JDK and Maven

*_HOME is consistent with the environment variable

5. Perform other configurations

Example Modify SSH configurations.

Configure the remote address, that is, run the project server.

Example Change the port number.

6. Install the plug-in

Install Maven Integration, Publish Over SSH, and use SSH to connect to the server where the JAR package is running.

7. Create a running space

  1. 1: indicates the name of the new space
  2. Two: You need to download the Maven plugin from the previous section

Configuration of 8.

1. Set the number of RESERVED JAR packages

The red circle here means that only 3 JARS of the latest version are kept. Otherwise the Jenkens server will crash due to lack of memory.

2. Configure the SVN address

Enter the SVN address at 1, and click 3 to display the following page. Enter the SVN account password. Then select the information filled in at 2 and 3.

3. Set the printing frequency

The following Settings are set to print for each commit.

This can also be a timed build. The configuration is as follows.

4. Add log output

5. Pack the command

6. Configure the SSH command

The above means that the following process is executed only if the packaging succeeds.

  • Position 1: Previous configuration of running file server.
  • 2: Jenkins server local release jar package path + JAR package name can be filled in target/*.jar
  • The package path can be set to Target
  • Four: SSH path to send the JAR package
  • 5: SSH command

The deployment principle is that Jenkin pulls the code locally, jars it to location 2, then uses SSH to execute 5 scripts on the path where the JAR package is sent to server 4.

The order at 5.

cd /usr/local/*
./*.sh stop
./*.sh start
Copy the code

The server startup script is also provided.

# Replace the path of the jar package here, no other code changes
APP_NAME=/usr/local/jar/*.jar
Use instructions to prompt for input parameters
usage() {
    echo "Usage: sh item.sh [start|stop|restart|status]"
    exit1}Check if the program is running
is_exist(){
  pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`
  # return 1 if none exists, return 0 if none exists
  if [ -z "${pid}" ]; then
   return 1
  else
    return 0
  fi
}

Start method
start(){
  is_exist
  if [ $? -eq 0 ]; then
    echo "${APP_NAME} is already running. pid=${pid}"
  else
    nohup  /usr/local/ JDK/jdk1.8.0 _231 / bin/Java - jar${APP_NAME} > earlywarning.out 2>&1 &
    echo "=============== program started successfully! = = = = = = = = = = = = = = ="	   
  fi
}

# stop method
stop(){
  is_exist
  if [ $? -eq "0" ]; then
    kill9 -$pid
   echo "============== program closed successfully! = = = = = = = = = = = = = ="
  else
    echo "${APP_NAME} is not running"
  fi  
}

Output the running status
status(){
  is_exist
  if [ $? -eq "0" ]; then
    echo "${APP_NAME} is running. Pid is ${pid}"
  else
    echo "${APP_NAME} is NOT running."
  fi
}

# to restart
restart(){
  stop
  sleep 5
  start
}

# According to the input parameters, select the corresponding method to execute, do not enter the instructions to execute
case "The $1" in
  "start")
    start
    ;;
  "stop")
    stop
    ;;
  "status")
    status
    ;;
  "restart")
    restart
    ;;
  *)
    usage
    ;;
esac
Copy the code

There is a bug in the above script, which requires you to fill in the absolute path of the JDK when starting.

nohup  /usr/local/jdk/jdk18.. 0 _231/bin/java -jar ${APP_NAME} > earlywarning.out 2> &1 &
Copy the code

3. Start and stop commands

Nohup java-jar Jenkins. War Closes Jenkinshttp://localhost:8080/jenkins/exitRestart Jenkieshttp://localhost:8080/jenkins/restartReload the configuration informationhttp://localhost:8080/jenkins/reload
Copy the code

Problem 4.

1. A problem

Jenkins start keeps showing Jenkins is starting, please wait…

See: blog.csdn.net/heatdeath/a…

Need you to enter the Jenkins working directory, open the Hudson. Model. UpdateCenter. The XMLhttp://updates.jenkins-ci.org/update-center.jsontohttp://mirror.xmission.com/jenkins/updates/update-center.json
Copy the code

2. Question 2

Resolve nohup: ignores input and appends output to “nohup.out” or nohup: ignores input redirection errors to standard output.

See: www.yayihouse.com/yayishuwu/c…

Run nohup Java -jar do_iptable.jar & run jar: nohup: ignores input and appends output to"nohup.out"Nohup Java -jar do_iptable.jar >/dev/null-jar do_iptable.jar > nohup: ignore the input redirection error and change the running mode to nohup Java -jar do_iptable.jar >/dev/null 2> &1& can.Copy the code

There’s a catch: Jenkin doesn’t pull jars from a custom start when the version number doesn’t change but the content does.