policeSecurity/policeSecurityServer/Jenkinsfile

56 lines
2.8 KiB
Plaintext
Raw Permalink Normal View History

2024-10-31 11:00:09 +08:00
pipeline {
agent any
tools {
jdk "jdk-17.0.11"
maven "apache-maven-3.8.8"
}
stages {
stage('拉取代码') {
steps {
echo '开始拉取代码'
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: '3', url: 'http://175.6.124.250:3100/luozhun/policeSecurity.git']])
echo '代码拉取成功'
}
}
stage('构建后台服务') {
steps{
echo '开始构建后台服务'
2024-10-31 11:03:00 +08:00
sh 'cd /var/jenkins_home/workspace/警保联动后端服务/policeSecurityServer && mvn clean -DskipTests=true package -P prod'
2024-10-31 11:00:09 +08:00
echo '后台服务构建完成'
}
}
stage('ssh远程推送代码'){
steps{
echo '开始推送构建产物'
script{
def remote = [:]
2024-10-31 11:08:44 +08:00
remote.name = 'server-118.253.177.137'
2024-10-31 11:06:20 +08:00
remote.host = '118.253.177.137'
remote.port = 55555
2024-10-31 11:00:09 +08:00
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: '4', passwordVariable: 'password', usernameVariable: 'username')]) {
remote.user = "${username}"
remote.password = "${password}"
}
sshCommand remote: remote, command: 'pwd=$(pwd) echo "ssh连接成功当前工作目录$(pwd)"'
2024-10-31 15:23:30 +08:00
sshCommand remote: remote, command: 'echo "停止后台服务..."'
sshCommand remote: remote, command: '''docker stop policeSecurityServer'''
sshCommand remote: remote, command: 'echo "后台服务已停止..."'
sshCommand remote: remote, command: 'echo "删除原来的server.jar..."'
sshRemove remote: remote, path: '/home/javaProject/policeSecurity/policeSecurityServer.jar'
sshCommand remote: remote, command: 'echo "server.jar删除成功!"'
2024-10-31 11:00:09 +08:00
sshCommand remote: remote, command: 'echo "将构建的server.jar发送到服务器..."'
2024-10-31 15:23:30 +08:00
sshPut remote: remote, from: '/var/jenkins_home/workspace/警保联动后端服务/policeSecurityServer/target/policeSecurityServer.jar', into: '/home/javaProject/policeSecurity'
2024-10-31 11:00:09 +08:00
sshCommand remote: remote, command: 'echo "server.jar发送成功!"'
2024-10-31 15:23:30 +08:00
sshCommand remote: remote, command: 'echo "启动后台服务..."'
sshCommand remote: remote, command: '''docker start policeSecurityServer'''
sshCommand remote: remote, command: 'echo "后台服务启动成功!"'
2024-10-31 11:00:09 +08:00
}
}
}
}
}