From 15d3ffbc0a260bca9bede936fc5ed409c1bd52f8 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Thu, 20 Aug 2026 13:00:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 8 +++++++- scripts/test-environment-pipeline-contract.test.mjs | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 830b43831..941569a2f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -28,6 +28,12 @@ def databaseMigrationPaths = ['deploy/sql/'] def downstreamResults = [:] +def environmentChoicesForJob(String jobBaseName) { + return jobBaseName == 'backend-java-dev' + ? ['development', 'test', 'staging', 'production'] + : ['test', 'development', 'staging', 'production'] +} + pipeline { // 总控流水线只识别变更并调度独立的服务 Job;实际 Maven、镜像和部署在 Jenkinsfile.service 中完成。 agent any @@ -52,7 +58,7 @@ pipeline { booleanParam(name: 'SERVICE_INTEGRATION', defaultValue: false, description: '第三方集成服务(integration-service)') booleanParam(name: 'SERVICE_EVENT_BRIDGE', defaultValue: false, description: '跨区域事件桥(event-bridge-service)') booleanParam(name: 'SERVICE_AUDIT', defaultValue: false, description: '审计服务(audit-service)') - choice(name: 'ENVIRONMENT', choices: ['test', 'development', 'staging', 'production'], description: '部署环境') + choice(name: 'ENVIRONMENT', choices: environmentChoicesForJob(env.JOB_BASE_NAME), description: '部署环境') booleanParam(name: 'DEPLOY', defaultValue: false, description: '各服务构建成功后是否独立部署') booleanParam(name: 'INITIALIZE_TEST_DATABASE', defaultValue: false, description: '仅 test:调度服务前幂等初始化测试数据库') booleanParam(name: 'SKIP_TESTS', defaultValue: false, description: '是否跳过测试;生产构建不建议勾选') diff --git a/scripts/test-environment-pipeline-contract.test.mjs b/scripts/test-environment-pipeline-contract.test.mjs index 9e533ae23..6604b6886 100644 --- a/scripts/test-environment-pipeline-contract.test.mjs +++ b/scripts/test-environment-pipeline-contract.test.mjs @@ -4,6 +4,8 @@ import test from 'node:test' const pipeline = (await readFile(new URL('../Jenkinsfile.service', import.meta.url), 'utf8')) .replaceAll('\r\n', '\n') +const coordinatorPipeline = (await readFile(new URL('../Jenkinsfile', import.meta.url), 'utf8')) + .replaceAll('\r\n', '\n') const directDeployScript = (await readFile(new URL('../deploy/scripts/deploy-built-service.sh', import.meta.url), 'utf8')) .replaceAll('\r\n', '\n') const ciMavenSettings = (await readFile(new URL('../deploy/maven/settings-ci.xml', import.meta.url), 'utf8')) @@ -16,6 +18,13 @@ test('test deployments compile packages without rerunning the full unit test sui assert.doesNotMatch(pipeline, /-Dmaven\.test\.skip=true/) }) +test('coordinator jobs present their own deployment environment as the default choice', () => { + assert.match(coordinatorPipeline, /jobBaseName == 'backend-java-dev'/) + assert.match(coordinatorPipeline, /\? \['development', 'test', 'staging', 'production'\]/) + assert.match(coordinatorPipeline, /: \['test', 'development', 'staging', 'production'\]/) + assert.match(coordinatorPipeline, /environmentChoicesForJob\(env\.JOB_BASE_NAME\)/) +}) + test('production deployments cannot skip tests', () => { assert.match(pipeline, /params\.ENVIRONMENT == 'production' && params\.SKIP_TESTS/) assert.match(pipeline, /error\('生产环境禁止跳过测试'\)/)