I read these links:
- Clear Jenkins build history ( clear build yesterday )
- How do I delete the builds 11 to 1717 in Jenkins?
- Jenkins: remove old builds with command line
First of all I work around Folders and these contains Views and these Jobs respectively.
Consider the following (to keep it simple):
- Folder:
jenkins-01View: alpha Job: Execute - Folder:
jenkins-02View: betax Job: Execute
From above two important observations:
- The
jenkins-01andjenkins-02folders are for two different projects. - The
ExecuteJob , can be repeated in many different Folders, but only about the name.
Now consider the following:
I can execute the Job through:
No custom View - therefore the default All default/generic view:
http://localhost:9090/job/jenkins-01/job/Execute/
Through many Views, let's say
http://localhost:9090/job/jenkins-01/view/alpha/job/Execute/http://localhost:9090/job/jenkins-01/view/betax/job/Execute/
And all the history or track of builds are in this path location:
/Users/username/ci/jenkins/Contents/jobs/jenkins-01/jobs/Execute
Script Console
Through the following:
def jobName = ???
println jobName;
//I used any of them
//def job = Jenkins.getInstance().getItemByFullName(jobName, Job.class)
//def job = Jenkins.instance.getItem(jobName)
if(job != null) {
job.getBuilds().each { println it }
//job.getBuilds().each { it.delete() }
//job.nextBuildNumber = 1
//job.save()
}
else
println 'job is NULL'
I tried many combinations about jobName (it about ???) and always I get null. So what should be the correct value for jobName?
Command Line
java -jar jenkins-cli.jar -s http://localhost:9090 delete-builds jobName=??? '1-56'
Again: what should be the correct value jobName?.
Remember: each Job is declared in a Folder and the Job's name (just the name) can be repeated in many Folders