Guard optional Jenkins vars in database import and export
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-05-08 23:26:14 +08:00
parent cf9fb5ac40
commit e390b72a0c
6 changed files with 94 additions and 56 deletions

View File

@@ -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)"