From 5e2e0530f1331ceb6c80555b5dd3aa4ed371035f Mon Sep 17 00:00:00 2001 From: nanxun Date: Tue, 11 Aug 2026 14:26:12 +0800 Subject: [PATCH] ci: recover sudo-owned build metadata --- Jenkinsfile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index ae29996..5586b26 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,6 +55,19 @@ pipeline { stages { stage('Checkout') { 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() checkout scm } @@ -375,6 +388,10 @@ pipeline { if [ -f "$DOCKER_CONFIG/config.json" ]; then : >"$DOCKER_CONFIG/config.json" 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)