ci: recover sudo-owned build metadata

This commit is contained in:
2026-08-11 14:26:12 +08:00
parent 40acd35ad7
commit 5e2e0530f1
Vendored
+17
View File
@@ -55,6 +55,19 @@ pipeline {
stages { stages {
stage('Checkout') { stage('Checkout') {
steps { steps {
withCredentials([usernamePassword(
credentialsId: "${NODE_CREDENTIALS}",
usernameVariable: 'JENKINS_NODE_USERNAME',
passwordVariable: 'JENKINS_NODE_PASSWORD'
)]) {
sh '''
set -euo pipefail
if [ -d "$WORKSPACE/.ci" ]; then
printf '%s\n' "$JENKINS_NODE_PASSWORD" | \
sudo -S -p '' chown -R -- "$(id -u):$(id -g)" "$WORKSPACE/.ci"
fi
'''
}
deleteDir() deleteDir()
checkout scm checkout scm
} }
@@ -375,6 +388,10 @@ pipeline {
if [ -f "$DOCKER_CONFIG/config.json" ]; then if [ -f "$DOCKER_CONFIG/config.json" ]; then
: >"$DOCKER_CONFIG/config.json" : >"$DOCKER_CONFIG/config.json"
fi fi
if [ -d "${CI_ROOT:-}" ]; then
printf '%s\n' "$JENKINS_NODE_PASSWORD" | \
sudo -S -p '' chown -R -- "$(id -u):$(id -g)" "$CI_ROOT" || true
fi
''' '''
} }
cleanWs(deleteDirs: true, notFailBuild: true) cleanWs(deleteDirs: true, notFailBuild: true)