This commit is contained in:
2026-08-20 12:34:10 +08:00
parent 3d57abf260
commit c83620a86a
3 changed files with 15 additions and 7 deletions
Vendored
+11 -6
View File
@@ -73,12 +73,17 @@ pipeline {
env.RESOLVED_ENVIRONMENT = resolvedEnvironment
echo "Job ${env.JOB_BASE_NAME} 使用部署环境: ${env.RESOLVED_ENVIRONMENT}"
String requestedRepository = params.IMAGE_REPOSITORY?.trim()
if (!requestedRepository || requestedRepository == 'registry.example.com/your-group/baiyue-firstleg') {
error('必须填写真实镜像仓库地址')
}
if (requestedRepository.contains('://') || !requestedRepository.contains('/')) {
error('IMAGE_REPOSITORY 格式错误:请填写 host[:port]/owner/image,不要包含 http:// 或 https://')
String requestedRepository
if (['development', 'test'].contains(env.RESOLVED_ENVIRONMENT)) {
requestedRepository = '172.31.198.7:10082/java-project/baiyue-firstleg'
} else {
requestedRepository = params.IMAGE_REPOSITORY?.trim()
if (!requestedRepository || requestedRepository == 'registry.example.com/your-group/baiyue-firstleg') {
error('预发布/生产环境必须填写真实镜像仓库地址')
}
if (requestedRepository.contains('://') || !requestedRepository.contains('/')) {
error('IMAGE_REPOSITORY 格式错误:请填写 host[:port]/owner/image,不要包含 http:// 或 https://')
}
}
echo "${env.RESOLVED_ENVIRONMENT} 环境使用共享镜像仓库: ${requestedRepository}"
env.RESOLVED_IMAGE_REPOSITORY = requestedRepository
+3 -1
View File
@@ -63,7 +63,9 @@ pipeline {
}
String sourceCommit = params.SOURCE_COMMIT?.trim()
String imageTag = params.IMAGE_TAG?.trim()
String imageRepository = params.IMAGE_REPOSITORY?.trim()
String imageRepository = ['development', 'test'].contains(params.ENVIRONMENT)
? '172.31.198.7:10082/java-project/baiyue-firstleg'
: params.IMAGE_REPOSITORY?.trim()
if (!sourceCommit) {
sourceCommit = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
@@ -24,6 +24,7 @@ test('production deployments cannot skip tests', () => {
test('Java builds use the shared builder pool and deploy on the target environment node', () => {
assert.match(pipeline, /agent \{ label 'java-builder' \}/)
assert.match(pipeline, /params\.ENVIRONMENT == 'development' \? 'java-dev' : 'master'/)
assert.match(pipeline, /\['development', 'test'\]\.contains\(params\.ENVIRONMENT\)/)
assert.match(pipeline, /172\.31\.198\.7:10082\/java-project\/baiyue-firstleg/)
assert.match(pipeline, /docker push \$\{image\}/)
assert.match(deployScript, /pull \$SERVICES/)