The springboot project uses jenkins for continuous integration

Keywords: Programming jenkins Java nexus shell

Step one:

Put jenkins.war in the tomcat/webapps directory

 

The second step:

1. Log in with root

2. Edit profile file: vi /etc/profile

3. Add: export JENKINS_HOME=/work/data

Save, exit and execute: source /etc/profile to make the configuration effective

 

The third step:

jenkins configures maven, jdk, git/svn paths

 

The fourth step:

jenkins to the specified path, use mvn to package the spring boot project to nexus

 

 

The fifth step:

Configuration item start stop script

#!/bin/bash
DEPLOY_PATH="/work/shell/deploy"
cd $DEPLOY_PATH
OLD_BUILD_ID=$BUILD_ID
echo $OLD_BUILD_ID
BUILD_ID=dontKillMe


sh datav-api.sh 0.0.1-Release

#Change back to the original build? ID value
BUILD_ID=$OLD_BUILD_ID
echo $BUILD_ID

Be careful:

After jenkins is built, all the started processes will be killed. Temporarily change the BUILD_ID value, so that jenkins will not find and end the background processes started by run.sh

 

The shell startup script code is as follows:

#!/bin/bash
VERSION=$1
NEXUS_URL="http://192.168.0.223:8081/nexus";
INSTALL_PATH="/work/www/datav-api"
GROUP_ID="com.eddue.biz"
ARTIFACT_ID="datav-api"
if [ -z "$VERSION" ]; then
    echo "ERROR: THE PROJECT'S VERSION MUST TO INPUT!"
    echo "ERROR: THE PROJECT'S DEPLOY EXIT!"
    exit 1
fi
if [ ! -d $INSTALL_PATH ];then
    mkdir -p $INSTALL_PATH
fi
cd $INSTALL_PATH
FILE_PATH=${INSTALL_PATH}"/"${ARTIFACT_ID}"-"${VERSION}
FILE_NAME=${ARTIFACT_ID}"-"${VERSION}".jar"
WORK_PATH=${INSTALL_PATH}"/work"
rm -rf $FILE_NAME
DOWNLOAD_URL=${NEXUS_URL}"/content/repositories/eddue/"${GROUP_ID//.//}"/"${ARTIFACT_ID}"/"${VERSION}"/"${FILE_NAME}
rm -rf $FILE_PATH
rm -rf $WORK_PATH
wget -c -q $DOWNLOAD_URL

DEPLOY_DIR=`pwd`
LOGS_DIR=""
if [ -n "$LOGS_FILE" ]; then
    LOGS_DIR=`dirname $LOGS_FILE`
else
    LOGS_DIR=$DEPLOY_DIR/logs
fi
if [ ! -d $LOGS_DIR ]; then
    mkdir -p $LOGS_DIR
fi
STDOUT_FILE=$LOGS_DIR/stdout.log

#Stop project first
PIDS=`ps -ef | grep java | grep "$FILE_NAME" | awk '{print $2}'`
if [ -z "$PIDS" ]; then
    echo "$FILE_NAME"
    echo "ERROR: The $SERVER_NAME does not started!"
else
   echo -e "Stopping the $SERVER_NAME ...\c"
   for PID in $PIDS ; do
      kill $PID > /dev/null 2>&1
   done

   COUNT=0
   while [ $COUNT -lt 1 ]; do
      echo -e ".\c"
      sleep 1
      COUNT=1
      for PID in $PIDS ; do
        PID_EXIST=`ps -f -p $PID | grep java`
        if [ -n "$PID_EXIST" ]; then
            COUNT=0
            break
        fi
      done
   done
   echo "Stop OK!\c"
fi




#Startup project

nohup java -jar  $FILE_NAME > $STDOUT_FILE 2>&1 &
sleep 10s
echo "OK!"
echo "$FILE_NAME"
PIDS2=`ps -ef | grep java | grep "$FILE_NAME" | awk '{print $2}'`
echo "PID: $PIDS2"
echo "STDOUT: $STDOUT_FILE"
echo "Start Over!"



Posted by rwfresh on Sat, 16 Nov 2019 08:15:57 -0800