Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the number of builds kept by Jenkins?

Tags:

jenkins

build

How can one set the number of builds kept by Jenkins for a specific job?

Jenkins keeps the last 30 builds of all our jobs. For a specific job, though, we would like to keep 60 builds, not 30.

I went to the job's configuration page, ticked "Discard old builds", entered "60" into "Max # of builds to keep", saved the job configuration, and restarted Jenkins.

After this change, Jenkins still keeps only 30 builds of the job. What am I doing wrong?

Related question: Why are only 30 builds kept? (I thought the default was not to delete any builds.)

We use Jenkins version 2.164.1 under Linux.

like image 901
user1387866 Avatar asked Jul 22 '19 12:07

user1387866


People also ask

How do you limit the number of builds stored in the build history in Jenkins?

This is a feature that is given to you by Jenkins so you can change the number of builds you want to keep. If you are using a Declarative pipeline you can just add this to your code: pipeline { options { buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30')) } ... }

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.


2 Answers

By default Jenkins keeps all builds in its disk and its advised that you use build discard to remove older builds to save disk space. This is a feature that is given to you by Jenkins so you can change the number of builds you want to keep.

If you are using a freestyle job change the max build as seen in the below screen shot FreeStyleJenkinsJob If you are using a Declarative pipeline you can just add this to your code:

pipeline {
  options {
    buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30'))
  }
  ...
}
like image 142
mbn217 Avatar answered Oct 19 '22 10:10

mbn217


The UI is limited to 30 builds. Try accessing older builds via the url with the build number, f.e.

https://myjenkins.uk/view/TWIN/job/myjob/insert-build-number-here/

You can also access the builds with stored artifacts on your jenkins master, f.e.:

/var/lib/jenkins/jobs/myjob/builds
like image 21
Frankenstein Avatar answered Oct 19 '22 10:10

Frankenstein