Skip to content

Commit

Permalink
Update build pipeline clean workspace to delete hidden files (#2460)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leonard <[email protected]>
  • Loading branch information
andrew-m-leonard authored Feb 9, 2021
1 parent 93b479a commit d7780e2
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pipelines/build/common/openjdk_build_pipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit d7780e2

Please sign in to comment.