在Ubuntu Jenkins部署中,可通过以下方式处理日志:
cat
、tail -f
、grep
、less
等工具查看/var/log/jenkins/jenkins.log
。/etc/logrotate.d/jenkins
文件,设置每日轮转、保留7天、压缩旧日志,示例配置:/var/log/jenkins/*.log {
daily
rotate 7
compress
missingok
notifempty
create 0644 root adm
postrotate
if [ -f /var/run/jenkins/jenkins.pid ]; then
kill -HUP $(cat /var/run/jenkins/jenkins.pid)
fi
endscript
}
0 * * * * find /var/log/jenkins/ -type f -name "*.log" -mtime +7 -exec rm -f {} \;