I want to schedule a job to clean old build so I have configure the below scripts but its working at Jenkins script console and not for Jenkins job configuration. While running the job I am getting below error:
Processing provided DSL script ERROR: (script, line 5) No such property: Jenkins for class: script Finished: FAILURE.my scripts is"
Code:
MAX_BUILDS = 2
for (job in Jenkins.instance.items) {
println job.name
def recent = job.builds.limit(MAX_BUILDS)
for (build in job.builds) {
if (!recent.contains(build)) {
println "Preparing to delete: " + build
build.delete()
}
}
}