devops-exercises/topics/cicd/solutions/remove_builds_solution.groovy
abregman 99c4e02ecf Rename exercises dir
Name it instead "topics" so it won't be
strange if some topics included "exercises" directory.
2022-08-02 01:53:56 +03:00

17 lines
437 B
Groovy

def removeOldBuilds(buildDirectory, days = 14) {
def wp = new File("${buildDirectory}")
def currentTime = new Date()
def backTime = currentTime - days
wp.list().each { fileName ->
folder = new File("${buildDirectory}/${fileName}")
if (folder.isDirectory()) {
def timeStamp = new Date(folder.lastModified())
if (timeStamp.before(backTime)) {
folder.delete()
}
}
}
}