You've already forked devops-exercises
Add a couple of new questions
This commit is contained in:
6
scenarios/jenkins/scripts/jobs_with_string.groovy
Normal file
6
scenarios/jenkins/scripts/jobs_with_string.groovy
Normal file
@@ -0,0 +1,6 @@
|
||||
def jobs = Jenkins.instance.items.findAll { job -> job.name =~ /"REMOVE_ME"/ }
|
||||
|
||||
jobs.each { job ->
|
||||
println job.name
|
||||
//job.delete()
|
||||
}
|
||||
16
scenarios/jenkins/scripts/old_builds.groovy
Normal file
16
scenarios/jenkins/scripts/old_builds.groovy
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user