From 1083c400707e1659681384a5bf4091796495ccf7 Mon Sep 17 00:00:00 2001 From: liuyihe <2513762445@qq.com> Date: Thu, 30 Jul 2026 22:23:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5b5ba69f3..18b8cda80 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -81,6 +81,16 @@ pipeline { stage('确定构建范围') { steps { script { + String requestedRepository = params.IMAGE_REPOSITORY?.trim() + if (!requestedRepository || requestedRepository == 'registry.example.com/your-group/baiyue-firstleg') { + requestedRepository = '8.163.30.128:10082/java-project/baiyue-firstleg' + echo "检测到旧的镜像仓库占位地址,已自动切换为测试环境 Gitea:${requestedRepository}" + } + if (requestedRepository.contains('://') || !requestedRepository.contains('/')) { + error('IMAGE_REPOSITORY 格式错误:请填写 host[:port]/owner/image,不要包含 http:// 或 https://') + } + env.RESOLVED_IMAGE_REPOSITORY = requestedRepository + List selected = [] if (params.BUILD_MODE == 'ALL') { selected = serviceModules @@ -144,11 +154,11 @@ pipeline { when { expression { env.NO_SERVICE_CHANGE != 'true' } } steps { script { - String registryHost = params.IMAGE_REPOSITORY.tokenize('/')[0] + String registryHost = env.RESOLVED_IMAGE_REPOSITORY.tokenize('/')[0] withCredentials([usernamePassword(credentialsId: env.REGISTRY_CREDENTIALS, usernameVariable: 'REGISTRY_USER', passwordVariable: 'REGISTRY_PASSWORD')]) { sh 'printf %s "$REGISTRY_PASSWORD" | docker login -u "$REGISTRY_USER" --password-stdin "' + registryHost + '"' env.SELECTED_SERVICES.split(',').each { service -> - String image = "${params.IMAGE_REPOSITORY}/${service}:${env.IMAGE_TAG}" + String image = "${env.RESOLVED_IMAGE_REPOSITORY}/${service}:${env.IMAGE_TAG}" sh "docker build -f deploy/docker/Dockerfile --build-arg BASE_IMAGE=${params.DOCKER_BASE_IMAGE} --build-arg JAR_FILE=${serviceJars[service]} -t ${image} ." sh "docker push ${image}" } @@ -158,7 +168,7 @@ pipeline { } } - stage('生产部署确认') { + stage('生产环境部署确认(仅 production 执行)') { when { allOf { expression { params.DEPLOY && params.ENVIRONMENT == 'production' && env.NO_SERVICE_CHANGE != 'true' } @@ -179,7 +189,7 @@ pipeline { script { String credentialId = "firstleg-${params.ENVIRONMENT}-env" withCredentials([file(credentialsId: credentialId, variable: 'DEPLOY_ENV_FILE')]) { - sh "sh deploy/scripts/deploy-services.sh '${params.ENVIRONMENT}' '${params.IMAGE_REPOSITORY}' '${env.IMAGE_TAG}' '${env.SELECTED_SERVICES}' \"\$DEPLOY_ENV_FILE\"" + sh "sh deploy/scripts/deploy-services.sh '${params.ENVIRONMENT}' '${env.RESOLVED_IMAGE_REPOSITORY}' '${env.IMAGE_TAG}' '${env.SELECTED_SERVICES}' \"\$DEPLOY_ENV_FILE\"" } } }