From ef9b43417e426eea339bebccc3728c7498c31de6 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sat, 25 Apr 2026 06:35:49 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20simplify=20pipeline=20=E2=80=94=20docker?= =?UTF-8?q?=20build=20handles=20full=20Maven=20build=20internally?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove separate Maven stage. The multi-stage Dockerfile already runs mvn inside a Linux container, so Windows Jenkins just runs docker build/push. Server-side docker login pre-configured; deploy only needs docker pull. Co-Authored-By: Claude Sonnet 4.6 --- Jenkinsfile | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 16d54b5..3479e70 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ pipeline { - agent none + agent any parameters { choice(name: 'SERVICE', choices: ['tenant-service', 'im-service', 'push-service', 'update-service'], description: '要构建的服务模块') @@ -18,31 +18,11 @@ pipeline { stages { stage('Checkout') { - agent any - steps { - checkout scm - stash name: 'source', includes: '**/*' - } - } - - stage('Build JAR') { - agent { - docker { - image 'maven:3.9-eclipse-temurin-21' - args '-v maven-repo:/root/.m2' - } - } - steps { - unstash 'source' - sh "mvn -pl ${params.SERVICE} -am -DskipTests -q clean package" - stash name: 'jar', includes: "${params.SERVICE}/target/*.jar,${params.SERVICE}/Dockerfile,Dockerfile" - } + steps { checkout scm } } stage('Docker Build & Push') { - agent any steps { - unstash 'jar' withCredentials([string(credentialsId: 'ACR_PASSWORD', variable: 'ACR_PASS')]) { script { def imageName = "${ACR_REGISTRY}/${ACR_NAMESPACE}/${params.SERVICE}:${params.IMAGE_TAG}" @@ -58,7 +38,6 @@ pipeline { } stage('Deploy to Production') { - agent any when { expression { return params.DEPLOY } } steps { withCredentials([sshUserPrivateKey(credentialsId: 'PROD_SSH_KEY', keyFileVariable: 'SSH_KEY')]) { @@ -66,12 +45,10 @@ pipeline { def svcName = params.SERVICE.replace('-service', '') def imageName = "${ACR_REGISTRY}/${ACR_NAMESPACE}/${params.SERVICE}:${params.IMAGE_TAG}" sh """ - ssh -i \${SSH_KEY} -o StrictHostKeyChecking=no ${PROD_USER}@${PROD_HOST} " - docker pull ${imageName} && - cd /opt/xuqm/deploy && - docker compose -f ${COMPOSE_FILE} up -d --no-deps ${svcName} && - docker image prune -f - " + ssh -i \${SSH_KEY} -o StrictHostKeyChecking=no ${PROD_USER}@${PROD_HOST} \ + "docker pull ${imageName} && \ + docker compose -f ${COMPOSE_FILE} up -d --no-deps ${svcName} && \ + docker image prune -f" """ } }