暂存提交

This commit is contained in:
2026-07-30 22:23:58 +08:00
parent 52d52909ee
commit 1083c40070
Vendored
+14 -4
View File
@@ -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\""
}
}
}