- 添加 JDK 1.8 工具配置 - 优化 Maven 构建命令,指定 JAVA_HOME - 新增部署前停止已运行项目的服务 - 修改部署步骤,使用 cp 命令替换 scp - 优化项目启动命令,增加内存配置
76 lines
2.7 KiB
Plaintext
76 lines
2.7 KiB
Plaintext
pipeline {
|
|
agent any
|
|
tools {
|
|
maven 'mvn39'
|
|
jdk 'jdk18'
|
|
}
|
|
stages {
|
|
stage('拉取代码') {
|
|
steps {
|
|
checkout([
|
|
$class: 'GitSCM',
|
|
branches: [[name: '*/dev']],
|
|
doGenerateSubmoduleConfigurations: false,
|
|
extensions: [],
|
|
submoduleCfg: [],
|
|
userRemoteConfigs: [[url: 'http://git.sinoecare.com/sinoecare/breed_service.git', credentialsId:'b42f8b48-95a4-4039-ae51-b1dff06d943b']]
|
|
])
|
|
}
|
|
}
|
|
stage('构建打包') {
|
|
steps {
|
|
withEnv(['JAVA_HOME=/home/java/jdk_1.8.0']){
|
|
sh 'mvn clean package -Dmaven.test.skip=true'
|
|
}
|
|
}
|
|
}
|
|
stage('部署') {
|
|
steps {
|
|
script {
|
|
echo 'Deploying...'
|
|
def projectDir = '/home/product/product_breed/app'
|
|
def jarName = 'breed-service.jar'
|
|
sh """
|
|
pid=`ps -ef | grep ${jarName}| grep -v grep | cut -c 9-16 `
|
|
if [ ! -n "$pid" ];then
|
|
echo "项目未启动,无需停止"
|
|
else
|
|
echo "kill 项目" ${jarName} "pid ---> " $pid
|
|
kill -9 $pid
|
|
sleep 2
|
|
fi
|
|
"""
|
|
sh "cp -f target/${jarName} ${projectDir}"
|
|
sh "cd ${projectDir}"
|
|
sh "BUILD_ID=dontKillMe setsid java -jar -Xmx500M -Xms500M ${jarName} --spring.profiles.active=dev --server.port=19998 >/dev/null 2>&1 &"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
post {
|
|
success {
|
|
script {
|
|
echo 'Deployment finished successfully.'
|
|
|
|
def currentTime = new Date().format('yyyy-MM-dd HH:mm:ss', TimeZone.getTimeZone('Asia/Shanghai'))
|
|
|
|
sh """
|
|
curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=1e734bc6-ab12-4272-8b15-cf92cb070f5b' \\
|
|
-H 'Content-Type: application/json' \\
|
|
-d '{
|
|
"msgtype": "markdown",
|
|
"markdown": {
|
|
"content": ">构建结果:农业项目后端构建完成!\\n
|
|
>完成时间:${currentTime}\\n
|
|
>构建时间:${currentBuild.durationString}"
|
|
}
|
|
}'
|
|
"""
|
|
}
|
|
}
|
|
failure {
|
|
echo 'Deployment failed.'
|
|
}
|
|
}
|
|
}
|