Files
pipeline-scripts/breed_jenkins
aixianling 233c3992f5 ci: 添加农业项目后端构建流程
- 新增 Jenkins 构建脚本,实现农业项目后端的自动构建和部署
- 包含代码拉取、构建打包和部署三个阶段
- 部署完成后通过企业微信 webhook 发送构建结果通知
2024-12-20 10:38:42 +08:00

59 lines
2.0 KiB
Plaintext

pipeline {
agent any
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 {
sh "mvn clean package -Dmaven.test.skip=true"
}
}
stage('部署') {
steps {
echo 'Deploying...'
def project_dir = "/home/product/product_breed/app"
def jar_name = "breed-service.jar"
sh "scp target/${jar_name} ${project_dir}"
sh "cd ${project_dir}"
sh "BUILD_ID=dontKillMe setsid java -jar -Xmx500M -Xms500M ${jar_name} --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.'
}
}
}