Add a couple of new questions

This commit is contained in:
abregman
2019-10-19 23:48:17 +03:00
parent 8ce4a0d9e1
commit cf03070b43
4 changed files with 121 additions and 13 deletions

View File

@@ -0,0 +1,6 @@
def jobs = Jenkins.instance.items.findAll { job -> job.name =~ /"REMOVE_ME"/ }
jobs.each { job ->
println job.name
//job.delete()
}

View File

@@ -0,0 +1,16 @@
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()
}
}
}
}

View File

@@ -3,3 +3,9 @@
Write the following scripts:
* Remove all the jobs which include the string "REMOVE_ME" in their name
* Remove builds older than 14 days
### Answer
* [Remove jobs which include specific string](jenkins/scripts/jobs_with_string.groovy)
* [Remove builds older than 14 days](jenkins/scripts/old_builds.groovy)