Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: remove old builds with command line

Tags:

jenkins

I delete old jenkins builds with rm where job is hosted:

my_job/builds/$ rm -rf [1-9]* 

These old builds are still visible in job page. How to remove them with command line?
(without the delete button in each build user interface)

like image 377
Philippe Blayo Avatar asked Oct 24 '12 15:10

Philippe Blayo


People also ask

How do I remove old builds in Jenkins?

Delete a Jenkins build via GUI. Go into the build you want to delete, and click the Delete this build button in the upper right corner. If you need to clean the Jenkins build history, and reset the build number back to 1, you can run a simple script in Jenkins Script Console.

How do I delete multiple builds in Jenkins?

There's a lot you can break using the script console. Delete the builds' folders from disk (by default in $JENKINS_HOME/jobs/JobName/builds/ , using the start time stamp as folder name) and restart Jenkins, or Reload Configuration From Disk.

How do I clean up my Jenkins build?

To clean up the workspace before build: Under Build Environment, check the box that says Delete workspace before build starts. To clean up the workspace after the build: Under the heading Post-build Actions select Delete workspace when build is done from the Add Post-build Actions drop down menu.

How do I get rid of Jenkins keep this build forever?

Normally if you click the build number/timestamp link (rather than the icon) to view its page, there should be a "Don't keep this build forever" button in the top right, where the "Delete" button normally is.


1 Answers

Here is another option: delete the builds remotely with cURL. (Replace the beginning of the URLs with whatever you use to access Jenkins with your browser.)

$ curl -X POST http://jenkins-host.tld:8080/jenkins/job/myJob/[1-56]/doDeleteAll 

The above deletes build #1 to #56 for job myJob.

If authentication is enabled on the Jenkins instance, a user name and API token must be provided like this:

$ curl -u userName:apiToken -X POST http://jenkins-host.tld:8080/jenkins/job/myJob/[1-56]/doDeleteAll 

The API token must be fetched from the /me/configure page in Jenkins. Just click on the "Show API Token..." button to display both the user name and the API token.

Edit: As pointed out by yegeniy in a comment below, one might have to replace doDeleteAll by doDelete in the URLs above to make this work, depending on the configuration.

like image 108
Erwan Legrand Avatar answered Sep 23 '22 00:09

Erwan Legrand