In nowadays, CI/CD makes the build running frequently. Especially when you using a tool like Jenkins, the files related to build can be increased rather quickly. And in a cloud working environment, most of the resources are shared, so if one instance is consuming more, it means other instances on the same (physical) server will consuming less, which might causing some problems, like unexpected exceptions, downtimes etc.

In order to keep the shared resource at a reasonable limit, we can utilize the build-in feature in Jenkins to delete the aged build artifacts.

To setup this, we need to configurate the job. In the configuration screen, we can set:

  • how many days: remove builds which happened xx days ago
  • how many builds: remove builds which happened xx times ago

keep-jenkins-builds

If we specify both, either one reaches to the limit will remove the old builds.