diff --git a/Jenkinsfile b/Jenkinsfile index f8248d9..c69930e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ pipeline { - agent any + agent none parameters { choice(name: 'APP', choices: ['tenant-platform', 'ops-platform'], description: '要构建的 Web 应用') @@ -18,22 +18,36 @@ pipeline { stages { stage('Checkout') { - steps { checkout scm } + agent any + steps { + checkout scm + stash name: 'source', includes: '**/*' + } } stage('Install & Build') { + agent { + docker { + image 'node:22-alpine' + args '-v yarn-cache:/root/.yarn' + } + } steps { + unstash 'source' dir("${params.APP}") { sh ''' yarn install --frozen-lockfile yarn build ''' } + stash name: 'dist', includes: "${params.APP}/dist/**,${params.APP}/Dockerfile" } } stage('Docker Build & Push') { + agent any steps { + unstash 'dist' withCredentials([string(credentialsId: 'ACR_PASSWORD', variable: 'ACR_PASS')]) { script { def imageName = "${ACR_REGISTRY}/${ACR_NAMESPACE}/web-${params.APP}:${params.IMAGE_TAG}" @@ -49,6 +63,7 @@ pipeline { } stage('Deploy to Production') { + agent any when { expression { return params.DEPLOY } } steps { withCredentials([sshUserPrivateKey(credentialsId: 'PROD_SSH_KEY', keyFileVariable: 'SSH_KEY')]) {