From 5850adb9220e3cea711ebcf4ef89852c7720778e Mon Sep 17 00:00:00 2001 From: Marc Dumais Date: Thu, 18 May 2023 10:20:14 -0400 Subject: [PATCH] A few tweaks to the new "cleanup" Jenkins file Looking at the run of the first run, I noticed that seemingly no `yarn--` or `theia-plugin-download` files were found or cleaned. It was confirmed in the Gitlab ticket that these two types of files are still present on the server. In this commit: - adapt the pattern we use for those two file types - handle the case of the "theia-plugin-download**" files differently, looking-for and deleting individual files that match the pattern rathern than directories. - various little improvements, guided by linter feedback Signed-off-by: Marc Dumais --- cleanup/Jenkinsfile | 85 +++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/cleanup/Jenkinsfile b/cleanup/Jenkinsfile index 3b0b340be..f76134644 100644 --- a/cleanup/Jenkinsfile +++ b/cleanup/Jenkinsfile @@ -1,63 +1,74 @@ -import groovy.json.JsonSlurper - pipeline { - agent none + agent { + label 'windows' + } options { timeout(time: 1, unit: 'HOURS') disableConcurrentBuilds() } stages { - stage('Cleanup') { - parallel { - stage('Cleanup Windows temp directory') { - agent { - label 'windows' - } - steps { - script { - cleanDirs('tmp/yarn', '\"%temp%\"', '(yarn--*)') - cleanDirs('tmp/plugin-download', '\"%temp%\"', '(theia-plugin-download*)') - cleanDirs('tmp/lighthouse', '\"%temp%\"', '(lighthouse.*)') - cleanDir('appdata/local/electron', '\"%LocalAppData%\"\\electron\\Cache') - cleanYarnCache('appdata/local/yarn', '\"%LocalAppData%\"\\Yarn\\Cache') - } - } + stage('Cleanup Windows temp directory') { + steps { + script { + listTemp('before cleanup', '%temp%') + cleanFiles('tmp/plugin-download', '%temp%', 'theia-plugin-download**') + cleanDirs('tmp/yarn', '%temp%', 'yarn--**') + cleanDirs('tmp/lighthouse', '%temp%', 'lighthouse.*') + listTemp('after cleanup', '%temp%') + cleanDir('appdata/local/electron', '\"%LocalAppData%\"\\electron\\Cache') + cleanYarnCache('appdata/local/yarn') } } } } } -def cleanDirs(String label, String parent, String pattern) { - bat "echo \"Before ${label} Cleanup:\"" - - bat "FOR /D /R ${parent} %%i in ${pattern} do echo \"%%i\"" - bat "FOR /D /R ${parent} %%i in ${pattern} do @rmdir /s /q \"%%i\"" +Object listTemp(String label, String temp) { + echo "in listTemp(): ${label}" + bat "DIR ${temp}" + return +} - bat "echo \"After ${label} Cleanup:\"" +Object cleanFiles(String label, String parent, String pattern) { + echo "in cleanFile() - clean: ${label} files" + echo "parent: ${parent}, pattern: ${pattern}" - bat "FOR /D /R ${parent} %%i in ${pattern} do echo \"%%i\"" + // use "returnStatus" option to avoid an exception being thrown if no + // matching files are found, failing the pipeline + s = bat( + script: "FORFILES /p ${parent} /m ${pattern} /C \"cmd /c Del /q @file\"", + returnStatus: true + ) + if (s != 0) { + echo "No ${pattern} file found... Good I guess" + } } -def cleanDir(String label, String parent) { - bat "echo \"Before ${label} Cleanup:\"" +Object cleanDirs(String label, String parent, String pattern) { + echo "Before ${label} Cleanup:" - bat "FOR /D /R ${parent} %%i in (*) do echo \"%%i\"" - bat "if exist ${parent} @rmdir /s /q ${parent}" + bat "FOR /D /R ${parent} %%i in (${pattern}) do echo \"%%i\"" + bat "FOR /D /R ${parent} %%i in (${pattern}) do @rmdir /s /q \"%%i\"" - bat "echo \"After ${label} Cleanup:\"" - - bat "FOR /D /R ${parent} %%i in (*) do echo \"%%i\"" + echo "After ${label} Cleanup:" + bat "FOR /D /R ${parent} %%i in (${pattern}) do echo \"%%i\"" + return } -def cleanYarnCache(String label, String parent) { - bat "echo \"Before ${label} Cleanup:\"" +Object cleanDir(String label, String parent) { + echo "Before ${label} Cleanup:" bat "FOR /D /R ${parent} %%i in (*) do echo \"%%i\"" - sh "yarn cache clean --all" - - bat "echo \"After ${label} Cleanup:\"" + bat "if exist ${parent} @rmdir /s /q ${parent}" + echo "After ${label} Cleanup:" bat "FOR /D /R ${parent} %%i in (*) do echo \"%%i\"" + return +} + +Object cleanYarnCache(String label) { + echo "Cleaning-up: ${label}" + sh 'yarn cache clean --all' + return }