Skip to content

Commit

Permalink
A few tweaks to the new "cleanup" Jenkins file
Browse files Browse the repository at this point in the history
Looking at the run of the first run, I noticed that seemingly no
`yarn--<random number>` or `theia-plugin-download<random identifier>`
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 <marc.dumais@ericsson.com>
  • Loading branch information
marcdumais-work committed May 26, 2023
1 parent 073a632 commit 5850adb
Showing 1 changed file with 48 additions and 37 deletions.
85 changes: 48 additions & 37 deletions cleanup/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 5850adb

Please sign in to comment.