This commit is contained in:
@@ -42,7 +42,7 @@ pipeline {
|
||||
if (commitHash && !(commitHash ==~ /^[0-9a-fA-F]{7,40}$/)) {
|
||||
error('COMMIT_HASH 只能填写 7 到 40 位十六进制 Git commit hash,当前值: ' + commitHash)
|
||||
}
|
||||
env.REQUESTED_COMMIT_HASH = commitHash ?: ''
|
||||
env.COMMIT_HASH = commitHash ?: ''
|
||||
def database = params.DATABASE?.trim()
|
||||
if (!database) {
|
||||
error('DATABASE 不能为空。')
|
||||
@@ -108,14 +108,15 @@ pipeline {
|
||||
sh '''
|
||||
bash -lc '
|
||||
set -euo pipefail
|
||||
if [[ -n "${REQUESTED_COMMIT_HASH}" ]]; then
|
||||
requested_commit="${COMMIT_HASH:-}"
|
||||
if [[ -n "${requested_commit}" ]]; then
|
||||
# Jenkins 先按 SCM 配置完成 checkout;如指定 commit,再拉取远端引用并切到该提交构建。
|
||||
git fetch --tags --prune origin "+refs/heads/*:refs/remotes/origin/*" || git fetch --all --tags --prune
|
||||
if [[ "$(git rev-parse --is-shallow-repository 2>/dev/null || echo false)" == "true" ]]; then
|
||||
git fetch --unshallow --tags || true
|
||||
fi
|
||||
git cat-file -e "${REQUESTED_COMMIT_HASH}^{commit}"
|
||||
resolved_commit="$(git rev-parse "${REQUESTED_COMMIT_HASH}^{commit}")"
|
||||
git cat-file -e "${requested_commit}^{commit}"
|
||||
resolved_commit="$(git rev-parse "${requested_commit}^{commit}")"
|
||||
git checkout --detach "${resolved_commit}"
|
||||
echo "[build-and-deploy] 使用指定 commit 构建: ${resolved_commit}"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user