From d7780e2ab5afaceb3a1c63fc0621025431963485 Mon Sep 17 00:00:00 2001 From: Andrew Leonard <31470007+andrew-m-leonard@users.noreply.github.com> Date: Tue, 9 Feb 2021 08:46:47 +0000 Subject: [PATCH] Update build pipeline clean workspace to delete hidden files (#2460) Signed-off-by: Andrew Leonard --- .../common/openjdk_build_pipeline.groovy | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/pipelines/build/common/openjdk_build_pipeline.groovy b/pipelines/build/common/openjdk_build_pipeline.groovy index ac8262397..23170f669 100644 --- a/pipelines/build/common/openjdk_build_pipeline.groovy +++ b/pipelines/build/common/openjdk_build_pipeline.groovy @@ -919,14 +919,23 @@ class Build { try { context.timeout(time: buildTimeouts.NODE_CLEAN_TIMEOUT, unit: "HOURS") { + // Clean non-hidden files first // Note: Underlying org.apache DirectoryScanner used by cleanWs has a bug scanning where it misses files containing ".." so use rm -rf instead // Issue: https://issues.jenkins.io/browse/JENKINS-64779 if (context.WORKSPACE != null && !context.WORKSPACE.isEmpty()) { - context.println "Cleaning workspace files: " + context.WORKSPACE + "/*" + context.println "Cleaning workspace non-hidden files: " + context.WORKSPACE + "/*" context.sh(script: "rm -rf " + context.WORKSPACE + "/*") } else { context.println "Warning: Unable to clean workspace as context.WORKSPACE is null/empty" } + + // Clean remaining hidden files using cleanWs + try { + context.println "Cleaning workspace hidden files using cleanWs: " + context.WORKSPACE + context.cleanWs notFailBuild: true, disableDeferredWipeout: true, deleteDirs: true + } catch (e) { + context.println "Failed to clean ${e}" + } } } catch (FlowInterruptedException e) { throw new Exception("[ERROR] Node Clean workspace timeout (${buildTimeouts.NODE_CLEAN_TIMEOUT} HOURS) has been reached. Exiting...") @@ -1029,8 +1038,16 @@ class Build { // Issue: https://issues.jenkins.io/browse/JENKINS-64779 if (context.WORKSPACE != null && !context.WORKSPACE.isEmpty()) { if (cleanWorkspaceAfter) { - context.println "Cleaning workspace files: " + context.WORKSPACE + "/*" + context.println "Cleaning workspace non-hidden files: " + context.WORKSPACE + "/*" context.sh(script: "rm -rf " + context.WORKSPACE + "/*") + + // Clean remaining hidden files using cleanWs + try { + context.println "Cleaning workspace hidden files using cleanWs: " + context.WORKSPACE + context.cleanWs notFailBuild: true, disableDeferredWipeout: true, deleteDirs: true + } catch (e) { + context.println "Failed to clean ${e}" + } } else if (cleanWorkspaceBuildOutputAfter) { context.println "Cleaning workspace build output files: " + context.WORKSPACE + "/workspace/build/src/build" context.sh(script: "rm -rf " + context.WORKSPACE + "/workspace/build/src/build")