From ba8479fa8dfff71495412d90ca442359cd635ef1 Mon Sep 17 00:00:00 2001 From: twi-devel Date: Thu, 22 Oct 2026 18:20:35 +0200 Subject: [PATCH] Fix Jenkins workspace cleanup with chmod before rm - Replace cleanWs with shell commands that fix permissions before deletion - Handle build/, build-coverage/, and coverage/ directories - Use chmod -R u+w to make files writable before rm -rf - Addresses 'Operation not permitted' errors on Jenkins host Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Entire-Checkpoint: 9acfd6cc578c --- Jenkinsfile | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e8c3be8..5e47c8f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,7 +27,24 @@ pipeline { steps { script { echo "Cleaning workspace to avoid corruption issues..." - cleanWs deleteDirs: true, disableDeferredWipeout: true + // Use shell command with chmod to handle permission issues + sh ''' + if [ -d "${WORKSPACE}/${BUILD_DIR}" ]; then + echo "Removing build directory with permission fix..." + chmod -R u+w "${WORKSPACE}/${BUILD_DIR}" 2>/dev/null || true + rm -rf "${WORKSPACE}/${BUILD_DIR}" + fi + if [ -d "${WORKSPACE}/${COVERAGE_BUILD_DIR}" ]; then + echo "Removing coverage build directory..." + chmod -R u+w "${WORKSPACE}/${COVERAGE_BUILD_DIR}" 2>/dev/null || true + rm -rf "${WORKSPACE}/${COVERAGE_BUILD_DIR}" + fi + if [ -d "${WORKSPACE}/coverage" ]; then + echo "Removing coverage output directory..." + chmod -R u+w "${WORKSPACE}/coverage" 2>/dev/null || true + rm -rf "${WORKSPACE}/coverage" + fi + ''' } } } @@ -112,7 +129,24 @@ pipeline { always { script { if (getContext(hudson.FilePath)) { - cleanWs deleteDirs: true, disableDeferredWipeout: true + // Use shell command with chmod to handle permission issues + sh ''' + if [ -d "${WORKSPACE}/${BUILD_DIR}" ]; then + echo "Final cleanup: Removing build directory..." + chmod -R u+w "${WORKSPACE}/${BUILD_DIR}" 2>/dev/null || true + rm -rf "${WORKSPACE}/${BUILD_DIR}" + fi + if [ -d "${WORKSPACE}/${COVERAGE_BUILD_DIR}" ]; then + echo "Final cleanup: Removing coverage build directory..." + chmod -R u+w "${WORKSPACE}/${COVERAGE_BUILD_DIR}" 2>/dev/null || true + rm -rf "${WORKSPACE}/${COVERAGE_BUILD_DIR}" + fi + if [ -d "${WORKSPACE}/coverage" ]; then + echo "Final cleanup: Removing coverage output..." + chmod -R u+w "${WORKSPACE}/coverage" 2>/dev/null || true + rm -rf "${WORKSPACE}/coverage" + fi + ''' } } }