Files
pipeline-scripts/breed_jenkins
aixianling 951566ca55 build(breed_jenkins): 更新 Jenkins 部署脚本
- 移除手动停止项目的步骤
- 使用 sshPublisher 插件进行文件传输和远程执行
- 调用远程脚本进行项目启动
2024-12-20 15:57:26 +08:00

70 lines
2.4 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'
def scriptPath = "/home/deploy/deploy_breed/run.sh"
sshPublisher(publishers: [sshPublisherDesc(configName: 'dev87', transfers: [sshTransfer(
sourceFiles: "${jarName}",
execCommand: "bash ${scriptPath}",
remoteDirectory: "${projectDir}")
], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
}
}
}
}
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.'
}
}
}