Bird
Raised Fist0
Jenkinsdevops~20 mins

Log management and rotation in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Log Rotation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Jenkins log rotation configuration effect
Given this Jenkins pipeline snippet for log rotation:
properties([
  buildDiscarder(logRotator(numToKeepStr: '5', daysToKeepStr: '10'))
])

What is the effect on the build logs?
AJenkins keeps only the last 10 builds and deletes logs older than 5 days.
BJenkins keeps only the last 5 builds and deletes logs older than 10 days.
CJenkins deletes all logs immediately after build completion.
DJenkins keeps all builds but deletes logs older than 10 days.
Attempts:
2 left
💡 Hint
Look at the parameters numToKeepStr and daysToKeepStr carefully.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Jenkins log rotation
Why is log rotation important in Jenkins?
ATo prevent disk space from filling up by old build logs.
BTo speed up build execution by caching logs.
CTo encrypt logs for security reasons.
DTo automatically restart Jenkins after each build.
Attempts:
2 left
💡 Hint
Think about what happens if logs keep growing without limit.
❓ Configuration
advanced
2:30remaining
Correct Jenkinsfile snippet for log rotation
Which Jenkinsfile snippet correctly configures log rotation to keep 7 builds and logs for 14 days?
Aproperties([buildDiscarder(logRotator('7', '14'))])
Bproperties([buildDiscarder(logRotator(numToKeep: 7, daysToKeep: 14))])
Cproperties([buildDiscarder(logRotator(numToKeepStr: '7', daysToKeepStr: '14'))])
Dproperties([buildDiscarder(logRotator(numToKeep: '7', daysToKeepStr: 14))])
Attempts:
2 left
💡 Hint
Check the parameter names and their types carefully.
❓ Troubleshoot
advanced
2:30remaining
Jenkins log rotation not deleting old logs
You configured Jenkins with:
properties([
  buildDiscarder(logRotator(numToKeepStr: '3', daysToKeepStr: '5'))
])

But old logs are not deleted after 5 days. What is the most likely cause?
AThe Jenkins master does not have permission to delete old log files.
BThe numToKeepStr parameter should be an integer, not a string.
CThe logRotator plugin is not installed in Jenkins.
DThe daysToKeepStr parameter only works for freestyle jobs, not pipelines.
Attempts:
2 left
💡 Hint
Consider file system permissions for Jenkins.
✅ Best Practice
expert
3:00remaining
Best practice for managing Jenkins logs in large environments
In a large Jenkins environment with many builds daily, what is the best practice for managing logs to ensure performance and disk space?
AIncrease disk space indefinitely to avoid deleting logs.
BDisable log rotation to keep all logs for audit purposes.
CManually delete logs weekly using shell scripts without Jenkins configuration.
DUse log rotation with reasonable limits and archive important logs to external storage.
Attempts:
2 left
💡 Hint
Think about automation and long-term storage.

Practice

(1/5)
1. What is the main purpose of log rotation in Jenkins?
easy
A. To move old logs and save disk space
B. To delete all Jenkins jobs automatically
C. To increase Jenkins build speed
D. To backup Jenkins configuration files

Solution

  1. Step 1: Understand what logs do in Jenkins

    Logs record Jenkins activity and can grow large over time.
  2. Step 2: Purpose of log rotation

    Log rotation moves or archives old logs to save disk space and keep the system tidy.
  3. Final Answer:

    To move old logs and save disk space -> Option A
  4. Quick Check:

    Log rotation = save space [OK]
Hint: Log rotation helps keep disk space free by moving old logs [OK]
Common Mistakes:
  • Thinking log rotation deletes Jenkins jobs
  • Confusing log rotation with backup
  • Believing log rotation speeds up builds
2. Which of the following is the correct syntax to configure log rotation using copytruncate in a Linux logrotate config for Jenkins logs?
easy
A. /var/log/jenkins/jenkins.log { truncatecopy weekly rotate 5 }
B. /var/log/jenkins/jenkins.log { copytruncate monthly rotate seven }
C. /var/log/jenkins/jenkins.log { copytruncate daily rotate 7 }
D. /var/log/jenkins/jenkins.log { copytruncate daily rotate seven }

Solution

  1. Step 1: Identify correct logrotate syntax

    The copytruncate option is valid and used to copy then truncate the log file without stopping Jenkins.
  2. Step 2: Check rotation frequency and count

    Using daily and rotate 7 is correct syntax for daily rotation keeping 7 files.
  3. Final Answer:

    Correct syntax with copytruncate, daily rotation, and rotate 7 -> Option C
  4. Quick Check:

    copytruncate + daily + rotate 7 = correct [OK]
Hint: copytruncate keeps Jenkins running during log rotation [OK]
Common Mistakes:
  • Using 'truncatecopy' instead of 'copytruncate'
  • Writing 'rotate seven' instead of 'rotate 7'
  • Using invalid rotation frequency like 'monthly' with wrong number
3. Given this logrotate config snippet for Jenkins logs:
/var/log/jenkins/jenkins.log {
    copytruncate
    weekly
    rotate 4
}
What will happen after 5 weeks of running this rotation?
medium
A. Jenkins service will stop during log rotation
B. All 5 weeks of logs are kept without deletion
C. Logs are deleted every week without keeping any backups
D. Only the latest 4 weekly logs are kept; older logs are deleted

Solution

  1. Step 1: Understand rotate count meaning

    Rotate 4 means keep 4 old log files; older ones get deleted.
  2. Step 2: Apply to 5 weeks

    After 5 weeks, the oldest log (week 1) is deleted, keeping only weeks 2-5.
  3. Final Answer:

    Only the latest 4 weekly logs are kept; older logs are deleted -> Option D
  4. Quick Check:

    rotate 4 means keep 4 logs [OK]
Hint: Rotate number = how many old logs to keep [OK]
Common Mistakes:
  • Thinking all logs are kept forever
  • Assuming logs delete immediately without backups
  • Believing Jenkins stops during copytruncate rotation
4. You configured Jenkins log rotation with copytruncate, but logs keep growing without rotation. What is the most likely cause?
medium
A. The Jenkins service is stopped
B. The logrotate service is not running or not scheduled
C. The copytruncate option is misspelled as copytrunc
D. The log file path is incorrect in the config

Solution

  1. Step 1: Check if logrotate runs

    If logrotate is not running or scheduled, logs won't rotate despite correct config.
  2. Step 2: Consider other causes

    Misspelling or wrong path cause errors, but usually logs won't grow if Jenkins stopped.
  3. Final Answer:

    The logrotate service is not running or not scheduled -> Option B
  4. Quick Check:

    Logrotate must run to rotate logs [OK]
Hint: Ensure logrotate runs regularly to rotate logs [OK]
Common Mistakes:
  • Assuming Jenkins must be stopped for rotation
  • Ignoring logrotate service status
  • Overlooking typos in config file
5. You want to rotate Jenkins logs daily without stopping Jenkins and keep logs for 10 days. Which logrotate config snippet achieves this safely?
hard
A. /var/log/jenkins/jenkins.log { copytruncate daily rotate 10 missingok notifempty }
B. /var/log/jenkins/jenkins.log { delaycompress weekly rotate 10 }
C. /var/log/jenkins/jenkins.log { copytruncate monthly rotate 10 }
D. /var/log/jenkins/jenkins.log { compress daily rotate 5 }

Solution

  1. Step 1: Identify safe rotation without stopping Jenkins

    copytruncate copies and truncates logs safely without stopping Jenkins.
  2. Step 2: Check rotation frequency and retention

    Daily rotation with rotate 10 keeps 10 days of logs. missingok and notifempty handle missing or empty logs safely.
  3. Final Answer:

    Config with copytruncate, daily rotation, rotate 10, missingok, notifempty -> Option A
  4. Quick Check:

    copytruncate + daily + rotate 10 = safe rotation [OK]
Hint: Use copytruncate for safe daily rotation without stopping Jenkins [OK]
Common Mistakes:
  • Using monthly or weekly instead of daily rotation
  • Not using copytruncate causing Jenkins stop
  • Setting rotate less than 10 days
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard