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)
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With