How to change the number of builds kept by Jenkins?

雨燕双飞 提交于 2020-05-29 11:06:06

问题


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.


回答1:


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



回答2:


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 If you are using a Declarative pipeline you can just add this to your code:

pipeline {
  options {
    buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30'))
  }
  ...
}


来源:https://stackoverflow.com/questions/57145735/how-to-change-the-number-of-builds-kept-by-jenkins

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!