固定 Jenkins Job 部署环境

This commit is contained in:
2026-09-03 17:43:52 +08:00
parent 6130a13b6b
commit 8911d4a242
3 changed files with 103 additions and 49 deletions
@@ -22,19 +22,26 @@ test('service pipeline keeps boolean operators on parseable Groovy continuation
})
test('test deployments compile packages without rerunning the full unit test suite', () => {
assert.match(pipeline, /params\.ENVIRONMENT == 'test' \|\| params\.SKIP_TESTS/)
assert.match(pipeline, /env\.RESOLVED_ENVIRONMENT == 'test' \|\| params\.SKIP_TESTS/)
assert.match(pipeline, /skipTestExecution \? '-DskipTests' : ''/)
assert.match(pipeline, /-pl \$\{env\.RESOLVED_SERVICE\} -am clean package/)
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'\]/)
test('coordinator and service jobs enforce their own deployment environments', () => {
assert.match(coordinatorPipeline, /case 'backend-java-dev':[\s\S]*?return 'development'/)
assert.match(coordinatorPipeline, /case 'backend-java':[\s\S]*?return 'test'/)
assert.match(coordinatorPipeline, /case 'backend-java-prod':[\s\S]*?return 'production'/)
assert.match(coordinatorPipeline, /environmentChoicesForJob\(env\.JOB_BASE_NAME\)/)
assert.match(coordinatorPipeline, /jobBaseName == 'backend-java-dev'[\s\S]*?'baiyue-firstleg-dev-'/)
assert.match(coordinatorPipeline, /downstreamJobPrefixForJob\(env\.JOB_BASE_NAME\)/)
assert.match(coordinatorPipeline, /env\.RESOLVED_ENVIRONMENT = resolvedEnvironment/)
assert.match(coordinatorPipeline, /env\.RESOLVED_JOB_PREFIX = resolvedJobPrefix/)
assert.match(pipeline, /startsWith\('baiyue-firstleg-dev-'\)[\s\S]*?return 'development'/)
assert.match(pipeline, /startsWith\('baiyue-firstleg-prod-'\)[\s\S]*?return 'production'/)
assert.match(pipeline, /startsWith\('baiyue-firstleg-'\)[\s\S]*?return 'test'/)
assert.match(pipeline, /environmentChoicesForServiceJob\(env\.JOB_BASE_NAME\)/)
assert.match(pipeline, /env\.RESOLVED_ENVIRONMENT = resolvedEnvironment/)
assert.doesNotMatch(pipeline, /params\.ENVIRONMENT ==/)
assert.doesNotMatch(pipeline, /contains\(params\.ENVIRONMENT\)/)
})
test('AUTO advances interrupted baselines and retries only their selected services', () => {
@@ -73,10 +80,10 @@ test('production deployments cannot skip tests', () => {
test('Java builds use the shared builder pool and serialize incremental target deployments', () => {
assert.match(pipeline, /agent \{ label 'java-builder' \}/)
assert.match(pipeline, /\['development', 'test'\]\.contains\(params\.ENVIRONMENT\)/)
assert.match(pipeline, /params\.ENVIRONMENT == 'development' \? 'java-dev' : 'java-test'/)
assert.match(pipeline, /\['development', 'test'\]\.contains\(env\.RESOLVED_ENVIRONMENT\)/)
assert.match(pipeline, /env\.RESOLVED_ENVIRONMENT == 'development' \? 'java-dev' : 'java-test'/)
assert.match(pipeline, /'TARGET_IS_LOCAL=true'/)
assert.match(pipeline, /String deploySlotLabel = "firstleg-\$\{params\.ENVIRONMENT\}-deploy-slot"/)
assert.match(pipeline, /String deploySlotLabel = "firstleg-\$\{env\.RESOLVED_ENVIRONMENT\}-deploy-slot"/)
assert.match(pipeline, /lock\(label: deploySlotLabel, quantity: 1, inversePrecedence: true\)/)
assert.match(pipeline, /deploy-built-service\.sh/)
assert.doesNotMatch(pipeline, /dev_deploy|test_deploy|TARGET_SSH_KEY/)
@@ -92,7 +99,7 @@ test('Java builds use the shared builder pool and serialize incremental target d
test('production only accepts skipped downstream tests for a coordinator-pinned commit', () => {
assert.match(pipeline, /boolean coordinatorPinnedCommit = params\.SOURCE_COMMIT\?\.trim\(\) as boolean/)
assert.match(pipeline, /params\.ENVIRONMENT == 'production' && params\.SKIP_TESTS && !coordinatorPinnedCommit/)
assert.match(pipeline, /env\.RESOLVED_ENVIRONMENT == 'production' && params\.SKIP_TESTS && !coordinatorPinnedCommit/)
assert.match(pipeline, /生产环境手工构建禁止跳过测试/)
})
@@ -106,8 +113,8 @@ test('development and test deployment locks are acquired before target executors
const nodeIndex = directDeployStage.indexOf('node(targetLabel)')
assert.match(directDeployStage, /agent none/)
assert.match(directDeployStage, /String targetLabel = params\.ENVIRONMENT == 'development' \? 'java-dev' : 'java-test'/)
assert.match(directDeployStage, /String serviceDeployResource = "firstleg-\$\{params\.ENVIRONMENT\}-\$\{env\.RESOLVED_SERVICE\}-deploy"/)
assert.match(directDeployStage, /String targetLabel = env\.RESOLVED_ENVIRONMENT == 'development' \? 'java-dev' : 'java-test'/)
assert.match(directDeployStage, /String serviceDeployResource = "firstleg-\$\{env\.RESOLVED_ENVIRONMENT\}-\$\{env\.RESOLVED_SERVICE\}-deploy"/)
assert.ok(serviceLockIndex >= 0, 'per-service deployment lock must exist')
assert.ok(lockIndex >= 0, 'deployment slot lock must exist')
assert.ok(nodeIndex >= 0, 'target node allocation must exist')