From 54ccb9fb40fb4d06b95076ffd94bd25bf6aa1e3e Mon Sep 17 00:00:00 2001 From: kurihada Date: Wed, 25 Feb 2026 12:17:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AE=80=E5=8C=96=20Jenkinsfile?= =?UTF-8?q?=EF=BC=8C=E7=A7=BB=E9=99=A4=E6=9C=AA=E9=85=8D=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E5=87=AD=E6=8D=AE=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 48 ++++++++++++------------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9766ac7..71c1356 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,9 +2,7 @@ pipeline { agent any environment { - APP_NAME = 'no-whatever' - DEPLOY_HOST = credentials('deploy-server-host') // 在 Jenkins 凭据中配置 - DEPLOY_USER = credentials('deploy-server-user') + APP_NAME = 'no-whatever' } triggers { @@ -20,44 +18,22 @@ pipeline { stage('Build Docker Image') { steps { - script { - docker.build("${APP_NAME}:${BUILD_NUMBER}") - docker.build("${APP_NAME}:latest") - } + sh "docker build -t ${APP_NAME}:${BUILD_NUMBER} -t ${APP_NAME}:latest ." } } stage('Deploy') { steps { - script { - // 方案 A: Jenkins 和部署机是同一台服务器 - sh """ - docker stop ${APP_NAME} || true - docker rm ${APP_NAME} || true - docker run -d \ - --name ${APP_NAME} \ - -p 3000:3000 \ - -v ${APP_NAME}-data:/app/data \ - --restart unless-stopped \ - ${APP_NAME}:latest - """ - - // 方案 B: 部署到远程服务器 (取消注释并注释掉方案 A) - // sh """ - // docker save ${APP_NAME}:latest | \ - // ssh ${DEPLOY_USER}@${DEPLOY_HOST} 'docker load' - // ssh ${DEPLOY_USER}@${DEPLOY_HOST} << 'EOF' - // docker stop ${APP_NAME} || true - // docker rm ${APP_NAME} || true - // docker run -d \ - // --name ${APP_NAME} \ - // -p 3000:3000 \ - // -v ${APP_NAME}-data:/app/data \ - // --restart unless-stopped \ - // ${APP_NAME}:latest - // EOF - // """ - } + sh """ + docker stop ${APP_NAME} || true + docker rm ${APP_NAME} || true + docker run -d \ + --name ${APP_NAME} \ + -p 3000:3000 \ + -v ${APP_NAME}-data:/app/data \ + --restart unless-stopped \ + ${APP_NAME}:latest + """ } } }