Guard optional Jenkins vars in database import and export
Some checks failed
CI / verify (push) Has been cancelled
Some checks failed
CI / verify (push) Has been cancelled
This commit is contained in:
@@ -116,8 +116,15 @@ pipeline {
|
||||
|
||||
chmod +x scripts/deploy/maintenance-on.sh scripts/deploy/maintenance-off.sh
|
||||
|
||||
export_dir="${WORKSPACE_EXPORT_DIRECTORY}"
|
||||
output_path="${export_dir}/${EFFECTIVE_EXPORT_NAME}"
|
||||
database="${DATABASE:?DATABASE 不能为空}"
|
||||
spacetime_server_url="${SPACETIME_SERVER_URL:-}"
|
||||
spacetime_server="${SPACETIME_SERVER:-}"
|
||||
spacetime_root_dir="${EFFECTIVE_SPACETIME_ROOT_DIR:-}"
|
||||
include_tables="${INCLUDE_TABLES:-}"
|
||||
server_backup_directory="${EFFECTIVE_SERVER_BACKUP_DIRECTORY:-}"
|
||||
export_dir="${WORKSPACE_EXPORT_DIRECTORY:-database-exports}"
|
||||
export_name="${EFFECTIVE_EXPORT_NAME:-spacetime-migration-${BUILD_NUMBER:-manual}.json}"
|
||||
output_path="${export_dir}/${export_name}"
|
||||
mkdir -p "${export_dir}"
|
||||
|
||||
maintenance_entered=0
|
||||
@@ -132,20 +139,20 @@ pipeline {
|
||||
}
|
||||
trap on_exit EXIT
|
||||
|
||||
scripts/deploy/maintenance-on.sh "database export ${DATABASE}"
|
||||
scripts/deploy/maintenance-on.sh "database export ${database}"
|
||||
maintenance_entered=1
|
||||
|
||||
args=(scripts/spacetime-export-migration-json.mjs --out "${output_path}" --database "${DATABASE}")
|
||||
if [[ -n "${SPACETIME_SERVER_URL}" ]]; then
|
||||
args+=(--server-url "${SPACETIME_SERVER_URL}")
|
||||
elif [[ -n "${SPACETIME_SERVER}" ]]; then
|
||||
args+=(--server "${SPACETIME_SERVER}")
|
||||
args=(scripts/spacetime-export-migration-json.mjs --out "${output_path}" --database "${database}")
|
||||
if [[ -n "${spacetime_server_url}" ]]; then
|
||||
args+=(--server-url "${spacetime_server_url}")
|
||||
elif [[ -n "${spacetime_server}" ]]; then
|
||||
args+=(--server "${spacetime_server}")
|
||||
fi
|
||||
if [[ -n "${EFFECTIVE_SPACETIME_ROOT_DIR}" ]]; then
|
||||
args+=(--root-dir "${EFFECTIVE_SPACETIME_ROOT_DIR}")
|
||||
if [[ -n "${spacetime_root_dir}" ]]; then
|
||||
args+=(--root-dir "${spacetime_root_dir}")
|
||||
fi
|
||||
if [[ -n "${INCLUDE_TABLES}" ]]; then
|
||||
args+=(--include "${INCLUDE_TABLES}")
|
||||
if [[ -n "${include_tables}" ]]; then
|
||||
args+=(--include "${include_tables}")
|
||||
fi
|
||||
args+=(--note "jenkins database export ${BUILD_TAG}")
|
||||
|
||||
@@ -153,10 +160,10 @@ pipeline {
|
||||
test -s "${output_path}"
|
||||
sha256sum "${output_path}" >"${output_path}.sha256"
|
||||
|
||||
if [[ -n "${EFFECTIVE_SERVER_BACKUP_DIRECTORY}" ]]; then
|
||||
mkdir -p "${EFFECTIVE_SERVER_BACKUP_DIRECTORY}"
|
||||
install -m 0640 "${output_path}" "${EFFECTIVE_SERVER_BACKUP_DIRECTORY}/${EFFECTIVE_EXPORT_NAME}"
|
||||
install -m 0640 "${output_path}.sha256" "${EFFECTIVE_SERVER_BACKUP_DIRECTORY}/${EFFECTIVE_EXPORT_NAME}.sha256"
|
||||
if [[ -n "${server_backup_directory}" ]]; then
|
||||
mkdir -p "${server_backup_directory}"
|
||||
install -m 0640 "${output_path}" "${server_backup_directory}/${export_name}"
|
||||
install -m 0640 "${output_path}.sha256" "${server_backup_directory}/${export_name}.sha256"
|
||||
fi
|
||||
|
||||
echo "[database-export] 完成: ${output_path}, source_commit=$(cat .jenkins-source-commit)"
|
||||
|
||||
@@ -181,11 +181,12 @@ pipeline {
|
||||
bash -lc '
|
||||
set -euo pipefail
|
||||
manual_filename="${MANUAL_INPUT_FILE_FILENAME:-}"
|
||||
confirm_input_file="${CONFIRM_INPUT_FILE:-}"
|
||||
if [[ -z "${manual_filename}" ]]; then
|
||||
echo "[database-import] 无法读取 MANUAL_INPUT_FILE_FILENAME,不能确认手动上传文件名。" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "${CONFIRM_INPUT_FILE}" != "${manual_filename}" ]]; then
|
||||
if [[ "${confirm_input_file}" != "${manual_filename}" ]]; then
|
||||
echo "[database-import] CONFIRM_INPUT_FILE 必须与手动上传文件原始文件名一致: ${manual_filename}" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -209,7 +210,20 @@ pipeline {
|
||||
|
||||
chmod +x scripts/deploy/maintenance-on.sh scripts/deploy/maintenance-off.sh
|
||||
|
||||
input_path="${EFFECTIVE_INPUT_FILE}"
|
||||
database="${DATABASE:?DATABASE 不能为空}"
|
||||
spacetime_server_url="${SPACETIME_SERVER_URL:-}"
|
||||
spacetime_server="${SPACETIME_SERVER:-}"
|
||||
spacetime_root_dir="${SPACETIME_ROOT_DIR:-}"
|
||||
server_backup_directory="${SERVER_BACKUP_DIRECTORY:-}"
|
||||
include_tables="${INCLUDE_TABLES:-}"
|
||||
chunk_size="${CHUNK_SIZE:-}"
|
||||
dry_run="${DRY_RUN:-true}"
|
||||
incremental="${INCREMENTAL:-true}"
|
||||
replace_existing="${REPLACE_EXISTING:-false}"
|
||||
run_smoke_test="${RUN_SMOKE_TEST:-true}"
|
||||
smoke_health_url="${SMOKE_HEALTH_URL:-}"
|
||||
|
||||
input_path="${EFFECTIVE_INPUT_FILE:?EFFECTIVE_INPUT_FILE 不能为空}"
|
||||
if [[ "${input_path}" != /* ]]; then
|
||||
input_path="${WORKSPACE}/${input_path}"
|
||||
fi
|
||||
@@ -218,8 +232,9 @@ pipeline {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
backup_dir="${PRE_IMPORT_BACKUP_DIRECTORY}"
|
||||
backup_path="${backup_dir}/${EFFECTIVE_PRE_IMPORT_BACKUP_NAME}"
|
||||
backup_dir="${PRE_IMPORT_BACKUP_DIRECTORY:-database-pre-import-backups}"
|
||||
backup_name="${EFFECTIVE_PRE_IMPORT_BACKUP_NAME:-pre-import-${BUILD_NUMBER:-manual}.json}"
|
||||
backup_path="${backup_dir}/${backup_name}"
|
||||
mkdir -p "${backup_dir}"
|
||||
|
||||
completed=0
|
||||
@@ -232,20 +247,20 @@ pipeline {
|
||||
}
|
||||
trap on_exit EXIT
|
||||
|
||||
scripts/deploy/maintenance-on.sh "database import ${DATABASE}"
|
||||
scripts/deploy/maintenance-on.sh "database import ${database}"
|
||||
|
||||
backup_args=(scripts/spacetime-export-migration-json.mjs --out "${backup_path}" --database "${DATABASE}")
|
||||
import_args=(scripts/spacetime-import-migration-json.mjs --in "${input_path}" --database "${DATABASE}")
|
||||
backup_args=(scripts/spacetime-export-migration-json.mjs --out "${backup_path}" --database "${database}")
|
||||
import_args=(scripts/spacetime-import-migration-json.mjs --in "${input_path}" --database "${database}")
|
||||
for args_name in backup_args import_args; do
|
||||
declare -n current_args="${args_name}"
|
||||
# server-url 明确指向目标实例时,不再同时透传默认 alias,避免 CLI 授权与 HTTP 导入落到不同目标。
|
||||
if [[ -n "${SPACETIME_SERVER_URL}" ]]; then
|
||||
current_args+=(--server-url "${SPACETIME_SERVER_URL}")
|
||||
elif [[ -n "${SPACETIME_SERVER}" ]]; then
|
||||
current_args+=(--server "${SPACETIME_SERVER}")
|
||||
if [[ -n "${spacetime_server_url}" ]]; then
|
||||
current_args+=(--server-url "${spacetime_server_url}")
|
||||
elif [[ -n "${spacetime_server}" ]]; then
|
||||
current_args+=(--server "${spacetime_server}")
|
||||
fi
|
||||
if [[ -n "${SPACETIME_ROOT_DIR}" ]]; then
|
||||
current_args+=(--root-dir "${SPACETIME_ROOT_DIR}")
|
||||
if [[ -n "${spacetime_root_dir}" ]]; then
|
||||
current_args+=(--root-dir "${spacetime_root_dir}")
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -254,25 +269,25 @@ pipeline {
|
||||
test -s "${backup_path}"
|
||||
sha256sum "${backup_path}" >"${backup_path}.sha256"
|
||||
|
||||
if [[ -n "${SERVER_BACKUP_DIRECTORY}" ]]; then
|
||||
mkdir -p "${SERVER_BACKUP_DIRECTORY}"
|
||||
install -m 0640 "${backup_path}" "${SERVER_BACKUP_DIRECTORY}/${EFFECTIVE_PRE_IMPORT_BACKUP_NAME}"
|
||||
install -m 0640 "${backup_path}.sha256" "${SERVER_BACKUP_DIRECTORY}/${EFFECTIVE_PRE_IMPORT_BACKUP_NAME}.sha256"
|
||||
if [[ -n "${server_backup_directory}" ]]; then
|
||||
mkdir -p "${server_backup_directory}"
|
||||
install -m 0640 "${backup_path}" "${server_backup_directory}/${backup_name}"
|
||||
install -m 0640 "${backup_path}.sha256" "${server_backup_directory}/${backup_name}.sha256"
|
||||
fi
|
||||
|
||||
if [[ -n "${INCLUDE_TABLES}" ]]; then
|
||||
import_args+=(--include "${INCLUDE_TABLES}")
|
||||
if [[ -n "${include_tables}" ]]; then
|
||||
import_args+=(--include "${include_tables}")
|
||||
fi
|
||||
if [[ -n "${CHUNK_SIZE}" ]]; then
|
||||
import_args+=(--chunk-size "${CHUNK_SIZE}")
|
||||
if [[ -n "${chunk_size}" ]]; then
|
||||
import_args+=(--chunk-size "${chunk_size}")
|
||||
fi
|
||||
if [[ "${DRY_RUN}" == "true" ]]; then
|
||||
if [[ "${dry_run}" == "true" ]]; then
|
||||
import_args+=(--dry-run)
|
||||
fi
|
||||
if [[ "${INCREMENTAL}" == "true" ]]; then
|
||||
if [[ "${incremental}" == "true" ]]; then
|
||||
import_args+=(--incremental)
|
||||
fi
|
||||
if [[ "${REPLACE_EXISTING}" == "true" ]]; then
|
||||
if [[ "${replace_existing}" == "true" ]]; then
|
||||
import_args+=(--replace-existing)
|
||||
fi
|
||||
import_args+=(--note "jenkins database import ${BUILD_TAG}")
|
||||
@@ -280,13 +295,13 @@ pipeline {
|
||||
node "${import_args[@]}"
|
||||
|
||||
# 导入成功后只做本机健康检查;业务级数据核验仍以迁移脚本的表级统计为准。
|
||||
if [[ "${RUN_SMOKE_TEST}" == "true" && -n "${SMOKE_HEALTH_URL}" ]]; then
|
||||
curl -fsS --max-time 10 "${SMOKE_HEALTH_URL}" >/dev/null
|
||||
if [[ "${run_smoke_test}" == "true" && -n "${smoke_health_url}" ]]; then
|
||||
curl -fsS --max-time 10 "${smoke_health_url}" >/dev/null
|
||||
fi
|
||||
|
||||
scripts/deploy/maintenance-off.sh
|
||||
completed=1
|
||||
echo "[database-import] 完成: dry_run=${DRY_RUN}, database=${DATABASE}, source_commit=$(cat .jenkins-source-commit)"
|
||||
echo "[database-import] 完成: dry_run=${dry_run}, database=${database}, source_commit=$(cat .jenkins-source-commit)"
|
||||
'
|
||||
'''
|
||||
}
|
||||
|
||||
@@ -57,10 +57,12 @@ pipeline {
|
||||
git checkout --force "origin/$sourceBranch"
|
||||
}
|
||||
git clean -ffdx
|
||||
git rev-parse HEAD | Set-Content -Encoding UTF8 .jenkins-source-commit
|
||||
$resolvedCommit = (git rev-parse HEAD).Trim()
|
||||
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
||||
[System.IO.File]::WriteAllText((Join-Path (Get-Location) '.jenkins-source-commit'), "$resolvedCommit`n", $utf8NoBom)
|
||||
'''
|
||||
script {
|
||||
env.SOURCE_COMMIT = readFile('.jenkins-source-commit').trim()
|
||||
env.SOURCE_COMMIT = readFile('.jenkins-source-commit').replace('\uFEFF', '').trim()
|
||||
env.EFFECTIVE_BUILD_VERSION = params.BUILD_VERSION?.trim() ? params.BUILD_VERSION.trim() : env.BUILD_NUMBER
|
||||
}
|
||||
}
|
||||
@@ -92,18 +94,18 @@ pipeline {
|
||||
throw '[stdb-build] 缺少 cargo。请先在 Windows 构建节点安装 Rust 工具链,并确保 cargo 在 PATH 中。'
|
||||
}
|
||||
# sccache 只是可选缓存;PATH 中存在但不可执行时必须回退到 rustc。
|
||||
$sccacheCommand = Get-Command sccache -ErrorAction SilentlyContinue
|
||||
$sccacheCommand = Get-Command sccache -ErrorAction SilentlyContinue
|
||||
$sccacheUsable = $false
|
||||
if ($sccacheCommand) {
|
||||
try {
|
||||
& $sccacheCommand.Source --version | Out-Host
|
||||
$sccacheUsable = $true
|
||||
} catch {
|
||||
Write-Host "[stdb-build] sccache 无法执行:$($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
if (-not $sccacheUsable) {
|
||||
Write-Host '[stdb-build] 未找到可用 sccache,改用 rustc 直接构建。'
|
||||
if ($sccacheCommand) {
|
||||
try {
|
||||
& $sccacheCommand.Source --version | Out-Host
|
||||
$sccacheUsable = $true
|
||||
} catch {
|
||||
Write-Host "[stdb-build] sccache 无法执行:$($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
if (-not $sccacheUsable) {
|
||||
Write-Host '[stdb-build] 未找到可用 sccache,改用 rustc 直接构建。'
|
||||
Remove-Item Env:RUSTC_WRAPPER -ErrorAction SilentlyContinue
|
||||
}
|
||||
npm run build:production-release -- --component spacetime-module --name "$env:EFFECTIVE_BUILD_VERSION"
|
||||
|
||||
Reference in New Issue
Block a user