Reset Jenkins workspaces before build deploy and migration

This commit is contained in:
kdletters
2026-05-01 22:57:00 +08:00
parent 1abec5754e
commit d796e7d491
6 changed files with 13 additions and 3 deletions

View File

@@ -113,6 +113,8 @@ pipeline {
sh '''
bash -lc '
set -euo pipefail
# 每条流水线开头先强制回到 SCM 检出的干净提交,避免固定源码目录残留改动影响本次执行。
git reset --hard HEAD
requested_commit="${COMMIT_HASH:-}"
if [[ -n "${requested_commit}" ]]; then
# Jenkins 先按 SCM 配置完成 checkout如指定 commit再拉取远端引用并切到该提交构建。

View File

@@ -56,6 +56,8 @@ pipeline {
sh """
bash -lc '
set -euo pipefail
# 导出流水线复用固定源码目录时,先清掉本地改动,确保执行的是 Jenkins SCM 检出的脚本。
git reset --hard HEAD
export_dir="${params.OUTPUT_DIRECTORY}"
if [[ -z "\${export_dir}" ]]; then
export_dir="database-exports"

View File

@@ -70,6 +70,8 @@ pipeline {
sh """
bash -lc '
set -euo pipefail
# 导入流水线复用固定源码目录时,先清掉本地改动,确保迁移脚本来自 Jenkins SCM 检出的版本。
git reset --hard HEAD
args=(scripts/spacetime-import-migration-json.mjs --in "${params.INPUT_FILE}")
if [[ -n "${params.DATABASE}" ]]; then
args+=(--database "${params.DATABASE}")

View File

@@ -115,6 +115,8 @@ pipeline {
sh """
bash -lc '
set -euo pipefail
# 部署流水线也先清回上游工作区的当前提交,避免复用目录中的本地改动影响部署脚本或产物选择。
git reset --hard HEAD
test -d "build/${params.BUILD_VERSION}"
deploy_script="${env.DEPLOY_SCRIPT_PATH}"
chmod +x "\${deploy_script}"