deploy
This commit is contained in:
parent
499c5be476
commit
cb3652fb1e
|
|
@ -1,65 +1,166 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
export deploy_path=/opt/builds/${JOB_NAME}/${BUILD_NUMBER}
|
||||
echo "--------moveFile start--------------"
|
||||
rm -rf $deploy_path
|
||||
mkdir -p $deploy_path
|
||||
cd $deploy_path
|
||||
rm -rf *.jar
|
||||
echo "workspace is ${WORKSPACE}"
|
||||
mv ${WORKSPACE}/sgzb-auth/target/sgzb-auth.jar $deploy_path
|
||||
mv ${WORKSPACE}/sgzb-gateway/target/sgzb-gateway.jar $deploy_path
|
||||
mv ${WORKSPACE}/sgzb-modules/sgzb-system/target/sgzb-modules-system.jar $deploy_path
|
||||
mv ${WORKSPACE}/sgzb-modules/sgzb-base/target/sgzb-modules-base.jar $deploy_path
|
||||
mv ${WORKSPACE}/sgzb-modules/sgzb-file/target/sgzb-modules-file.jar $deploy_path
|
||||
mv ${WORKSPACE}/sgzb-modules/sgzb-material/target/sgzb-modules-material.jar $deploy_path
|
||||
chmod 777 *.jar
|
||||
echo "--------moveFile end--------------"
|
||||
export sgzb_auth_enable=true
|
||||
export sgzb_gateway_enable=true
|
||||
export sgzb_modules_system_enable=true
|
||||
export sgzb_modules_base_enable=true
|
||||
export sgzb_modules_file_enable=false
|
||||
export sgzb_modules_material_enable=true
|
||||
|
||||
export deploy_path=/opt/webapps/NingXiaJiJu
|
||||
export sgzb_auth_jar=sgzb-auth.jar
|
||||
export sgzb_gateway_jar=sgzb-gateway.jar
|
||||
export sgzb_modules_system_jar=sgzb-modules-system.jar
|
||||
export sgzb_modules_base_jar=sgzb-modules-base.jar
|
||||
export sgzb_modules_file_jar=sgzb-modules-file.jar
|
||||
export sgzb_modules_material_jar=sgzb-modules-material.jar
|
||||
|
||||
#export jars_path = /home/jenkins/workspace/NingXiaJiJu/bonus-auth/target
|
||||
export sgzb_auth_port=29200
|
||||
export sgzb_gateway_port=28080
|
||||
export sgzb_modules_system_port=29201
|
||||
export sgzb_modules_base_port=29301
|
||||
export sgzb_modules_file_port=9300
|
||||
export sgzb_modules_material_port=29302
|
||||
|
||||
export app_workspace=/home/jenkins/workspace/NingXiaJiJu
|
||||
if($auth_service_enable);then
|
||||
echo "--------auth开始启动--------------"
|
||||
echo "--------删除auth开始--------------"
|
||||
P_ID=`ps -ef | grep -w $sgzb_auth_jar | grep -v "grep" | awk '{print $2}'`
|
||||
if [ "$P_ID" == "" ]; then
|
||||
echo "===auth service process not exists or stop success"
|
||||
else
|
||||
kill -9 $P_ID
|
||||
echo "auth service killed success"
|
||||
fi
|
||||
nohup /usr/lib/jvm/jdk1.8.0_381/bin/java -jar $sgzb_auth_jar >/dev/null 2>&1 &
|
||||
sgzb_auth_pid=`lsof -i:$sgzb_auth_port|grep "LISTEN"|awk '{print $2}'`
|
||||
until [ -n "$sgzb_auth_pid" ]
|
||||
do
|
||||
sgzb_auth_pid=`lsof -i:$sgzb_auth_port|grep "LISTEN"|awk '{print $2}'`
|
||||
done
|
||||
echo "auth service pid is $sgzb_auth_pid"
|
||||
echo "--------auth_service 启动成功--------------"
|
||||
fi
|
||||
|
||||
if($sgzb_gateway_enable);then
|
||||
echo "--------gateway 开始启动--------------"
|
||||
echo "--------删除gateway开始--------------"
|
||||
P_ID=`ps -ef | grep -w $sgzb_gateway_jar | grep -v "grep" | awk '{print $2}'`
|
||||
if [ "$P_ID" == "" ]; then
|
||||
echo "===gateway process not exists or stop success"
|
||||
else
|
||||
kill -9 $P_ID
|
||||
echo "gateway killed success"
|
||||
fi
|
||||
echo "--------删除gateway开始2-------------- $sgzb_gateway_port"
|
||||
nohup /usr/lib/jvm/jdk1.8.0_381/bin/java -jar $sgzb_gateway_jar >/dev/null 2>&1 &
|
||||
echo "--------删除gateway开始3-------------- $sgzb_gateway_port"
|
||||
sgzb_gateway_pid=`lsof -i:$sgzb_gateway_port|grep "LISTEN"|awk '{print $2}'`
|
||||
echo "--------删除gateway开始4-------------- $sgzb_gateway_pid"
|
||||
until [ -n "$sgzb_gateway_pid" ]
|
||||
do
|
||||
echo "--------删除gateway开始5-------------- $sgzb_gateway_pid"
|
||||
sgzb_gateway_pid=`lsof -i:$sgzb_gateway_port|grep "LISTEN"|awk '{print $2}'`
|
||||
echo "--------删除gateway开始6-------------- $sgzb_gateway_pid"
|
||||
done
|
||||
echo "gateway pid is $sgzb_gateway_pid"
|
||||
echo "--------gateway 启动成功--------------"
|
||||
fi
|
||||
|
||||
|
||||
app_source_jars=(
|
||||
"sgzb-api/sgzb-api-system/target/sgzb-api-system-3.6.3.jar"
|
||||
"sgzb-auth/target/sgzb-auth.jar"
|
||||
"sgzb-gateway/target/sgzb-gateway.jar"
|
||||
"sgzb-modules/sgzb-base/target/sgzb-base.jar"
|
||||
"sgzb-modules/sgzb-file/target/sgzb-file.jar"
|
||||
"sgzb-modules/sgzb-gen/target/sgzb-gen.jar"
|
||||
"sgzb-modules/sgzb-job/target/sgzb-job.jar"
|
||||
"sgzb-modules/sgzb-material/target/sgzb-material.jar"
|
||||
"sgzb-modules/sgzb-settlement/target/sgzb-settlement.jar"
|
||||
"sgzb-modules/sgzb-system/target/sgzb-system.jar"
|
||||
"sgzb-visual/target/sgzb-visual-monitor.jar"
|
||||
)
|
||||
if($sgzb_modules_system_enable);then
|
||||
echo "--------sgzb_modules_system 开始启动--------------"
|
||||
echo "--------删除sgzb_modules_system开始--------------"
|
||||
P_ID=`ps -ef | grep -w $sgzb_modules_system_jar | grep -v "grep" | awk '{print $2}'`
|
||||
if [ "$P_ID" == "" ]; then
|
||||
echo "===sgzb_modules_system process not exists or stop success"
|
||||
else
|
||||
kill -9 $P_ID
|
||||
echo "sgzb_modules_system killed success"
|
||||
fi
|
||||
echo "--------sgzb_modules_system开始部署--------------"
|
||||
nohup /usr/lib/jvm/jdk1.8.0_381/bin/java -jar $sgzb_modules_system_jar >/dev/null 2>&1 &
|
||||
sgzb_modules_system_pid=`lsof -i:$sgzb_modules_system_port|grep "LISTEN"|awk '{print $2}'`
|
||||
until [ -n "$sgzb_modules_system_pid" ]
|
||||
do
|
||||
sgzb_modules_system_pid=`lsof -i:$sgzb_modules_system_port|grep "LISTEN"|awk '{print $2}'`
|
||||
done
|
||||
echo "sgzb_modules_system pid is $sgzb_modules_system_pid"
|
||||
echo "--------sgzb_modules_system 启动成功--------------"
|
||||
fi
|
||||
|
||||
for source_jar in "${app_source_jars[@]}"; do
|
||||
cp -f ${app_workspace}/${source_jar} $deploy_path
|
||||
echo "copied ${app_workspace}/${source_jar}/auth/target/auth.jar to $deploy_path"
|
||||
done
|
||||
# Define an array of JAR files to run
|
||||
jars=("sgzb-auth.jar" "sgzb-gateway.jar" "sgzb-modules-base.jar" "sgzb-modules-file.jar"
|
||||
"sgzb-modules-gen.jar" "sgzb-modules-job.jar" "sgzb-modules-material.jar"
|
||||
"sgzb-modules-settlement.jar" "sgzb-modules-system.jar" "sgzb-system.jar"
|
||||
"sgzb-visual-monitor.jar" "sentinel-dashboard-1.8.1.jar")
|
||||
if($sgzb_modules_base_enable);then
|
||||
echo "--------sgzb_modules_base 开始启动--------------"
|
||||
echo "--------删除sgzb_modules_base开始--------------"
|
||||
P_ID=`ps -ef | grep -w $sgzb_modules_base_jar | grep -v "grep" | awk '{print $2}'`
|
||||
if [ "$P_ID" == "" ]; then
|
||||
echo "===sgzb_modules_base process not exists or stop success"
|
||||
else
|
||||
kill -9 $P_ID
|
||||
echo "sgzb_modules_base killed success"
|
||||
fi
|
||||
echo "--------sgzb_modules_base开始部署--------------"
|
||||
nohup /usr/lib/jvm/jdk1.8.0_381/bin/java -jar $sgzb_modules_base_jar >/dev/null 2>&1 &
|
||||
sgzb_modules_base_pid=`lsof -i:$sgzb_modules_base_port|grep "LISTEN"|awk '{print $2}'`
|
||||
until [ -n "$sgzb_modules_base_pid" ]
|
||||
do
|
||||
sgzb_modules_base_pid=`lsof -i:$sgzb_modules_base_port|grep "LISTEN"|awk '{print $2}'`
|
||||
done
|
||||
echo "sgzb_modules_base pid is $sgzb_modules_base_pid"
|
||||
echo "--------sgzb_modules_base 启动成功--------------"
|
||||
fi
|
||||
|
||||
# Stop all running JARs
|
||||
for jar in "${jars[@]}"; do
|
||||
P_ID=$(pgrep -f "$jar")
|
||||
# 如果该项目已经在服务器上启动则kill掉
|
||||
echo "原应用程序$jar进程id:$P_ID"
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "==$jar service process does not exist"
|
||||
else
|
||||
# 尝试优雅地关闭应用程序
|
||||
kill -9 "$P_ID"
|
||||
wait "$P_ID" 2>/dev/null
|
||||
if($sgzb_modules_file_enable);then
|
||||
echo "--------sgzb_modules_file 开始启动--------------"
|
||||
echo "--------删除sgzb_modules_file开始--------------"
|
||||
P_ID=`ps -ef | grep -w $sgzb_modules_file_jar | grep -v "grep" | awk '{print $2}'`
|
||||
if [ "$P_ID" == "" ]; then
|
||||
echo "===sgzb_modules_file process not exists or stop success"
|
||||
else
|
||||
kill -9 $P_ID
|
||||
echo "sgzb_modules_file killed success"
|
||||
fi
|
||||
echo "--------sgzb_modules_file开始部署--------------"
|
||||
nohup /usr/lib/jvm/jdk1.8.0_381/bin/java -jar $sgzb_modules_file_jar >/dev/null 2>&1 &
|
||||
sgzb_modules_file_pid=`lsof -i:$sgzb_modules_file_port|grep "LISTEN"|awk '{print $2}'`
|
||||
until [ -n "$sgzb_modules_file_pid" ]
|
||||
do
|
||||
sgzb_modules_file_pid=`lsof -i:$sgzb_modules_file_port|grep "LISTEN"|awk '{print $2}'`
|
||||
done
|
||||
echo "sgzb_modules_file pid is $sgzb_modules_file_pid"
|
||||
echo "--------sgzb_modules_file 启动成功--------------"
|
||||
fi
|
||||
|
||||
# 检查进程是否仍在运行
|
||||
if ! ps -p "$P_ID" > /dev/null; then
|
||||
echo "$jar service process was terminated gracefully"
|
||||
else
|
||||
# 如果优雅关闭失败,则强制杀死进程
|
||||
kill -9 "$P_ID"
|
||||
echo "$jar service process was killed forcefully"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Iterate over the JAR files array
|
||||
for jar in "${jars[@]}"; do
|
||||
echo "Running $jar..."
|
||||
# Assuming java is in your PATH and the JARs are in the current directory
|
||||
nohup /usr/lib/jvm/jdk1.8.0_381/bin/java -jar "$jar" >/dev/null 2>&1 &
|
||||
|
||||
done
|
||||
|
||||
echo "All JARs have been run successfully."
|
||||
if($sgzb_modules_material_enable);then
|
||||
echo "--------sgzb_modules_material 开始启动--------------"
|
||||
echo "--------删除sgzb_modules_material开始--------------"
|
||||
P_ID=`ps -ef | grep -w $sgzb_modules_material_jar | grep -v "grep" | awk '{print $2}'`
|
||||
if [ "$P_ID" == "" ]; then
|
||||
echo "===sgzb_modules_material process not exists or stop success"
|
||||
else
|
||||
kill -9 $P_ID
|
||||
echo "sgzb_modules_material killed success"
|
||||
fi
|
||||
echo "--------sgzb_modules_material开始部署--------------"
|
||||
nohup /usr/lib/jvm/jdk1.8.0_381/bin/java -jar $sgzb_modules_material_jar >/dev/null 2>&1 &
|
||||
sgzb_modules_material_pid=`lsof -i:$sgzb_modules_material_port|grep "LISTEN"|awk '{print $2}'`
|
||||
until [ -n "$sgzb_modules_material_pid" ]
|
||||
do
|
||||
sgzb_modules_material_pid=`lsof -i:$sgzb_modules_material_port|grep "LISTEN"|awk '{print $2}'`
|
||||
done
|
||||
echo "sgzb_modules_material pid is $sgzb_modules_material_pid"
|
||||
echo "--------sgzb_modules_material 启动成功--------------"
|
||||
fi
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo "--------moveFile start--------------"
|
||||
#cp -rf ${WORKSPACE}/scripts/sonar-project.properties ${WORKSPACE}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
// 设置自定义JDK路径,因为每个项目可能需要不同版本的jdk
|
||||
JAVA_HOME = '/usr/lib/jvm/jdk1.8.0_381'
|
||||
JOBNAME="${JOB_NAME}"
|
||||
JENKINS_NODE_COOKIE = "dontKillMe"
|
||||
}
|
||||
stages {
|
||||
stage('Check out') {
|
||||
steps {
|
||||
withCredentials([usernamePassword(credentialsId: 'f7070987-9b49-4ae1-af6d-53a3bf26799b', passwordVariable: 'Max@2023', usernameVariable: 'bonus')]) {
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
branches: [[name: '*/dev-nx']],
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: '']],
|
||||
submoduleCfg: [],
|
||||
userRemoteConfigs: [[url: 'http://192.168.0.56:3000/bonus/devicesmgt.git']]
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Move file') {
|
||||
steps {
|
||||
echo 'move file start!'
|
||||
sh 'chmod 777 ${WORKSPACE}/scripts/*'
|
||||
// 如果需要拷贝文件,打开并编写以下脚本
|
||||
// sh '${WORKSPACE}/scripts/moveFile.sh'
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
echo 'build start!'
|
||||
sh 'env JAVA_HOME=$JAVA_HOME /usr/local/src/apache-maven-3.9.4/bin/mvn clean package'
|
||||
}
|
||||
}
|
||||
stage('Sonar scan') {
|
||||
steps {
|
||||
script {
|
||||
echo 'sonar scan start!'
|
||||
def scannerHome = tool 'sonar-scanner'
|
||||
withSonarQubeEnv('sonarqube-server') {
|
||||
sh "/usr/local/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner " +
|
||||
"-Dsonar.projectKey=${JOB_NAME} " +
|
||||
"-Dsonar.projectName=${JOB_NAME} " +
|
||||
"-Dsonar.sourceEncoding=UTF-8 " +
|
||||
"-Dsonar.language=java " +
|
||||
"-Dsonar.projectVersion=1.0 " +
|
||||
"-Dsonar.sources=. " +
|
||||
"-Dsonar.java.source=1.8 " +
|
||||
"-Dsonar.java.target=1.8 " +
|
||||
"-Dsonar.scm.disabled=true " +
|
||||
"-Dsonar.exclusions=test/**,node_modules/**,static/**,**/*.js,**/*.html,**/*.css,**/*.jar " +
|
||||
"-Dsonar.java.binaries=**/target/classes"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
echo 'deploy start!'
|
||||
sh '''BUILD_ID=DONTKILLME sh ${WORKSPACE}/scripts/deploy.sh'''
|
||||
}
|
||||
}
|
||||
stage('Dingding') {
|
||||
steps {
|
||||
echo 'Dingding start!'
|
||||
script {
|
||||
def webhookUrl = 'https://oapi.dingtalk.com/robot/send?access_token=eae0af98514a0db9a9a0d5cd8e337d13e7c16cd81d4a90b503e465a573020add' //替换为你自己的钉钉机器人Webhook地址
|
||||
def message = "${JOB_NAME} TEST已完成: ${env.BUILD_URL} \n 到Sonarqube查看问题:http://192.168.0.56:9000/dashboard?id=${JOB_NAME} \n 查看新包: http://192.168.0.56/${JOB_NAME}/${BUILD_NUMBER} "
|
||||
echo "${message}"
|
||||
sh "curl -H 'Content-Type: application/json' -d '{\"msgtype\": \"text\", \"text\": {\"content\": \"${message}\"}, \"at\": {\"atMobiles\": [\"张三,李四\"], \"isAtAll\": true}}' ${webhookUrl}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
P_ID=$(pgrep -f SgzbAuthApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbAuthApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
P_ID=$(pgrep -f SgzbFileApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbFileApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
P_ID=$(pgrep -f SgzbGatewayApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbGatewayApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
P_ID=$(pgrep -f SgzbGenApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbGenApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
P_ID=$(pgrep -f SgzbJobApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbJobApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
P_ID=$(pgrep -f SgzbMonitorApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbMonitorApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
P_ID=$(pgrep -f SgzbBaseApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbBaseApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
P_ID=$(pgrep -f SgzbMaterialApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbMaterialApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
P_ID=$(pgrep -f SgzbSettlementApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbSettlementApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
|
||||
P_ID=$(pgrep -f SgzbSystemApplication)
|
||||
if [ -z "$P_ID" ]; then
|
||||
echo "SgzbSystemApplication is not running"
|
||||
else
|
||||
kill -9 "$P_ID"
|
||||
fi
|
||||
|
||||
Loading…
Reference in New Issue