Add Jenkins local deployment test parameters

This commit is contained in:
Codex
2026-04-29 12:03:22 +08:00
parent 37a03dc994
commit 1dee5f72d7
4 changed files with 93 additions and 14 deletions

View File

@@ -10,7 +10,10 @@ pipeline {
string(name: 'AGENT_LABEL', defaultValue: 'built-in', description: '构建节点标签')
string(name: 'GENARRATIVE_WORKSPACE_ROOT', defaultValue: '', description: '源码根目录,留空则使用当前 Jenkins 工作区')
string(name: 'BUILD_VERSION', defaultValue: '', description: '发布版本号,留空则使用 Jenkins BUILD_NUMBER')
string(name: 'DATABASE', defaultValue: 'genarrative_pipeline_local_test', description: '发布包默认 SpacetimeDB database')
string(name: 'API_PORT', defaultValue: '8082', description: '发布包内 api-server 端口')
string(name: 'WEB_PORT', defaultValue: '25001', description: '发布包内静态网站端口,默认 25001')
string(name: 'SPACETIME_PORT', defaultValue: '3101', description: '发布包内本地 SpacetimeDB 端口')
booleanParam(name: 'CLEAR_DATABASE', defaultValue: false, description: '部署时是否清空 SpacetimeDB 数据后再发布 wasm')
booleanParam(name: 'RUN_NPM_CI', defaultValue: false, description: '构建前是否执行 npm ci')
string(name: 'DEPLOY_JOB_NAME', defaultValue: 'Genarrative-Deploy', description: '部署流水线作业名')
@@ -30,6 +33,29 @@ pipeline {
env.EFFECTIVE_BUILD_VERSION = params.BUILD_VERSION?.trim() ? params.BUILD_VERSION.trim() : env.BUILD_NUMBER
// 允许 Jenkins Job 直接指定固定源码目录,未指定时回退到当前工作区。
env.WORKSPACE_ROOT = params.GENARRATIVE_WORKSPACE_ROOT?.trim() ? params.GENARRATIVE_WORKSPACE_ROOT.trim() : pwd()
def database = params.DATABASE?.trim()
if (!database) {
error('DATABASE 不能为空。')
}
if (!(database ==~ /^[0-9A-Za-z._-]+$/)) {
error("DATABASE 只能包含数字、字母、点、下划线和短横线,当前值: ${database}")
}
env.EFFECTIVE_DATABASE = database
def apiPort = params.API_PORT?.trim()
if (!apiPort) {
error('API_PORT 不能为空。')
}
if (!(apiPort ==~ /^[0-9]+$/)) {
error("API_PORT 必须是数字端口,当前值: ${apiPort}")
}
if (apiPort.length() > 5) {
error("API_PORT 必须在 1-65535 之间,当前值: ${apiPort}")
}
def parsedApiPort = apiPort.toInteger()
if (parsedApiPort < 1 || parsedApiPort > 65535) {
error("API_PORT 必须在 1-65535 之间,当前值: ${apiPort}")
}
env.EFFECTIVE_API_PORT = apiPort
def webPort = params.WEB_PORT?.trim()
if (!webPort) {
error('WEB_PORT 不能为空。')
@@ -46,6 +72,21 @@ pipeline {
}
// 后续构建与下游部署都使用校验后的同一端口值,避免参数空格导致上下游不一致。
env.EFFECTIVE_WEB_PORT = webPort
def spacetimePort = params.SPACETIME_PORT?.trim()
if (!spacetimePort) {
error('SPACETIME_PORT 不能为空。')
}
if (!(spacetimePort ==~ /^[0-9]+$/)) {
error("SPACETIME_PORT 必须是数字端口,当前值: ${spacetimePort}")
}
if (spacetimePort.length() > 5) {
error("SPACETIME_PORT 必须在 1-65535 之间,当前值: ${spacetimePort}")
}
def parsedSpacetimePort = spacetimePort.toInteger()
if (parsedSpacetimePort < 1 || parsedSpacetimePort > 65535) {
error("SPACETIME_PORT 必须在 1-65535 之间,当前值: ${spacetimePort}")
}
env.EFFECTIVE_SPACETIME_PORT = spacetimePort
// 记录当前构建节点名,部署阶段必须回到同一节点读取本地 build 目录。
env.SOURCE_NODE_NAME = env.NODE_NAME
}
@@ -73,8 +114,13 @@ pipeline {
sh """
bash -lc '
set -euo pipefail
# 构建并部署流水线显式透传 Web 端口,确保部署包默认监听 25001同时允许 Jenkins 参数覆盖
npm run deploy:rust:remote -- --skip-upload --name "${env.EFFECTIVE_BUILD_VERSION}" --web-port "${env.EFFECTIVE_WEB_PORT}"
# 构建并部署流水线显式透传本地测试参数,避免发布包回退到默认库名或端口
npm run deploy:rust:remote -- --skip-upload \
--name "${env.EFFECTIVE_BUILD_VERSION}" \
--database "${env.EFFECTIVE_DATABASE}" \
--api-port "${env.EFFECTIVE_API_PORT}" \
--web-port "${env.EFFECTIVE_WEB_PORT}" \
--spacetime-port "${env.EFFECTIVE_SPACETIME_PORT}"
test -d "build/${env.EFFECTIVE_BUILD_VERSION}"
'
"""