jenkinsloggingjobspurge

Jenkins - Puge build history logs - Configure a job to keep just the last 100 builds history and delete the rest


I have a Jenkins Job that is running periodically (Every minute).

As so, I end up with thousands of logs that doesn't really matters to me and overload the space disk.

Is there a way to configure that job, in a way it will keep just the last 100 builds and delete the old ones?

I know this is possible manually, But I am looking for a way that I don't have to do it myself every time, I want the job, or another one to do it automatically.


Solution

  • You do not need to do that manually, you just configure the job to retain the # of builds to retain during creating the job. This again can be done when you create the job itself through a rest api, all you have to do is to set the appropriate values in the job's config.xml. You configure the job once and never have to worry, Jenkins automatically takes care of the clean-up.

    Configuring builds to retain in Jenkins UI

    Note Once you configure the job, the next run will be over the threshold and trigger deleting the excess job logs.

    Also, since LTS 2.204.6: Add globally configured build discarders that delete old builds not marked as "keep forever" even if there is no, or a less aggressive, per-project build discarder configured, executed periodically and after a build finishes