This commit is contained in:
2026-08-20 13:00:39 +08:00
parent b029f4ce28
commit 15d3ffbc0a
2 changed files with 16 additions and 1 deletions
Vendored
+7 -1
View File
@@ -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: '是否跳过测试;生产构建不建议勾选')
@@ -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\('生产环境禁止跳过测试'\)/)