Jenkins: how to remove log but keep build ?

Related searches

We have builds that generate a lot of logs. It takes space thus we have to tell jenkins to remove old builds. It is a problem because we therefore lose the long-term statistics.

I am thinking of removing or emptying the "log" file of each build older than a week and tell jenkins not to delete old build.

Is there a clean way of achieving the same ?

I saw there is a Delete Log Plugin but I didn't personally use it.

However in my work I did similar thing by just create another job, which go to the Jenkins master server, sort the builds, pick up the ones that need to be cleaned up, and remove the log file. Should be faily easy to do with any scripting language.

[JENKINS-51229] Log Discarder to delete log files generated by , However, this log discarder will delete the logs for older builds, but does not a distinction between keeping artifacts and keeping the build. In Jenkins 2+ (mine is 2.89) in the Config of every Job there is now an option "Discard Old Builds" where you can specify if you want to delete builds older than X days and/or only keep X latest builds – Andrejs Feb 6 '18 at 8:01

Haven't found a really clean way that exists yet, but using groovy from within Jenkins is arguably cleaner than deleting from the filesystem outside of Jenkins.

This example groovy script will delete all logs from builds of the "test_dummy" job that are older than 180 days.

import jenkins.model.*;
def days = 180
def jobName = "test_dummy"
def j = Jenkins.instance.getItemByFullName(jobName);
j.getBuilds().byTimestamp(1, System.currentTimeMillis() - (1000L * 60 * 60 * 24 * days)).each { it.getLogFile().delete(); it.getLogFile().createNewFile() }

So get the job, get all the builds for it in your timestamp range, then get and delete all the log files. I'm also going and creating an empty file in their place, though I'm sure if I dug deeper I could find a way just to truncate to 0.

Using Jenkins getJobNames(), you could get all the jobs in Jenkins and then loop through them if you wanted. Depending on how you do backups, you could tie it to run before you do backups to save space.

Clear Jenkins build history ( clear build yesterday ), If you need to clean the Jenkins build history, and reset the build number back to 1, you can nextBuildNumber = 1 To remove an entire job and build history remove the job folder, e.g.: Log in. or. Name. Email. By clicking “ Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy. The existing, mainstream implementation already includes a distinction between keeping artifacts and keeping the build. Adding another distinction to it about keeping logs seems consistent with the existing role/scope and would provide a generally useful option; especially in the context of JENKINS-48344 or other cases where Jenkins users encounter disk space issues because of log size.

Best Strategy for Disk Space Management: Clean Up Old Builds , Jenkins builds can pile up and cause disk space to grow out of control. numToKeep: If not -1, only this number of build logs are kept. -mtime +$age” where age is the oldest date you want to keep the build (in days). than the chosen date, and you can choose to delete what you feel is safe to remove. Can I remove old builds safely by deleting the contents of Stack Exchange Network Stack Exchange network consists of 176 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Purge Job History, Plugin will recurse into all Jobs/Folder and delete the builds depending on your selection. Example Screenshots;. Logs. Depending on the Job/� You can configure how to discard builds in more detail than the default 'Discard Old Build' function. Other than # of builds and days, you can specify build status to discard/keep. For older builds, you can configure interval to keep builds (once in a month, once in ten builds). You can also use logfile size to decide if delete a old build. Usage

Workspace Cleanup, Pre-pipeline. The plugin provides a build wrapper (Delete workspace before build starts) and a post build step (Delete workspace when build is� If this is a maven project then in the left side panel, you can see the option as delete maven project. If this is a git or other project then in the job dashboard just right the of the job name you will find an arrow mark dropdown which one option delete the organization. click on that and your job will be deleted.

It’s also possible to purge selectively from the filesystem using “find $dir -mtime +$age” where age is the oldest date you want to keep the build (in days). This will get you a list of files older than the chosen date, and you can choose to delete what you feel is safe to remove.