From 8d97ebf8d8dd7c2c301a3afd7da0c13b56215b9e Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Fri, 24 Apr 2026 21:42:52 +0800 Subject: [PATCH] ci: use Docker agent for Maven build stage on Windows Jenkins Run mvn inside maven:3.9-eclipse-temurin-21 Linux container via Docker Pipeline plugin; Docker/SSH deploy stages remain on native agent so Docker Desktop socket is available for image push and SSH for deploy. Co-Authored-By: Claude Sonnet 4.6 --- Jenkinsfile | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 45e29d8..16d54b5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ pipeline { - agent any + agent none parameters { choice(name: 'SERVICE', choices: ['tenant-service', 'im-service', 'push-service', 'update-service'], description: '要构建的服务模块') @@ -18,21 +18,31 @@ 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 { - sh """ - mvn -pl ${params.SERVICE} -am -DskipTests -q clean package - """ + unstash 'source' + sh "mvn -pl ${params.SERVICE} -am -DskipTests -q clean package" + stash name: 'jar', includes: "${params.SERVICE}/target/*.jar,${params.SERVICE}/Dockerfile,Dockerfile" } } 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}" @@ -48,6 +58,7 @@ pipeline { } stage('Deploy to Production') { + agent any when { expression { return params.DEPLOY } } steps { withCredentials([sshUserPrivateKey(credentialsId: 'PROD_SSH_KEY', keyFileVariable: 'SSH_KEY')]) {