Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable log rotation in Jenkins for weekly?

I am trying to enable the log rotation for jenkins. Because the log file occupied more memory space. Is there any plugins or method to do it?

like image 671
jass Avatar asked Jul 24 '15 12:07

jass


People also ask

How often logs should be rotated?

Each file should be rotated weekly. The log rotation job runs nightly, though, so this can be changed to daily for a specific log file if desired. The three commands that specify how often rotation should take place are daily, weekly and monthly. Keep four sets of log files.

How do I rotate a syslog?

If you want to rotate /var/log/syslog it needs to be listed in a logrotate config file somewhere, and you just run logrotate . If it rotated recently, then logrotate -f to force it to do it again. So, you need that in a file, normally either /etc/logrotate. conf or as a file snippet in /etc/logrotate.

How do I monitor Jenkins logs?

If you want to want to monitor all the Jenkins instances, then you need to install filebeat in all the instances and ships the application log to logstash. Here, we will ship the application logs of one Jenkins instance only. Below is the filebeat. yml to monitor jenkins log file.

Do logs rotate?

In information technology, log rotation is an automated process used in system administration in which log files are compressed, moved (archived), renamed or deleted once they are too old or too big (there can be other metrics that can apply here).


3 Answers

Job Configuration -->Discard Old Builds:

There is default Log Rotation strategy:

Jenkins log rotation

I suggest you to click the "Advanced" button to know more about this log rotation strategy.

like image 142
mainframer Avatar answered Oct 24 '22 19:10

mainframer


Other answers here are referring to the logs generated by the individual jobs,
but if you are asking about Jenkins' main jenkins.log file (generated by the Jenkins-server),
a bug related to that was fixed on Apr-2015 -
see here:

  • Add a logrotate definition to the Jenkins Debian package definition (similar to Apache, cron-apt, aptitude and apt)

Also, you can read more about logging in Jenkins, here:

  • Jenkins - Logging
like image 43
Gonen Avatar answered Oct 24 '22 19:10

Gonen


It's a default Jenkins feature and you do not need a plugin to achieve what you require. Go to job config page and check the flag at "Discard old builds" (it is right under the job's description. Then select log rotation as strategy and specify the '7' as a value for 'Days to keep builds'.

like image 32
Zloj Avatar answered Oct 24 '22 19:10

Zloj