chore: pass web port through jenkins deploy

This commit is contained in:
2026-04-26 22:44:04 +08:00
parent 8448913d2f
commit ea550de6a1
4 changed files with 108 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ pipeline {
string(name: 'SOURCE_WORKSPACE_ROOT', defaultValue: '', description: '上游源码根目录')
string(name: 'BUILD_VERSION', defaultValue: '', description: '待部署版本号')
string(name: 'DEPLOY_DIRECTORY', defaultValue: '/var/lib/jenkins/deploy/Genarrative', description: '固定部署目录')
string(name: 'WEB_PORT', defaultValue: '25001', description: '静态网站监听端口,默认 25001上游构建并部署流水线会透传同名参数')
booleanParam(name: 'CLEAR_DATABASE', defaultValue: false, description: '部署时是否清空 SpacetimeDB 数据后再发布 wasm')
booleanParam(name: 'RUN_DEPLOY_HOOKS_WITH_SUDO', defaultValue: true, description: 'start.sh / stop.sh 是否通过 sudo -n 执行')
string(name: 'EXPECTED_UPSTREAM_JOB', defaultValue: '', description: '允许触发本作业的上游作业名')
@@ -53,6 +54,26 @@ pipeline {
error('SOURCE_NODE_NAME 不能为空。')
}
def webPort = params.WEB_PORT?.trim()
if (!webPort) {
error('WEB_PORT 不能为空。')
}
if (!(webPort ==~ /^[0-9]+$/)) {
error("WEB_PORT 必须是数字端口,当前值: ${webPort}")
}
if (webPort.length() > 5) {
error("WEB_PORT 必须在 1-65535 之间,当前值: ${webPort}")
}
def parsedWebPort = webPort.toInteger()
if (parsedWebPort < 1 || parsedWebPort > 65535) {
error("WEB_PORT 必须在 1-65535 之间,当前值: ${webPort}")
}
// 部署脚本只接收校验后的端口值,避免手工参数前后空格传到 Bash。
env.EFFECTIVE_WEB_PORT = webPort
if (upstreamCause && !actualUpstreamJob?.trim()) {
error('无法从上游触发原因中解析作业名,请检查 Jenkins Pipeline Build Step 插件版本与触发链。')
}
@@ -85,6 +106,7 @@ pipeline {
deploy_args=(
--source-dir "build/${params.BUILD_VERSION}"
--deploy-dir "${params.DEPLOY_DIRECTORY}"
--web-port "${env.EFFECTIVE_WEB_PORT}"
)
if [[ "${params.CLEAR_DATABASE}" == "true" ]]; then
deploy_args+=(--clear-database)