Bird
Raised Fist0
Jenkinsdevops~10 mins

Log management and rotation in Jenkins - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the log rotation days in Jenkins pipeline.

Jenkins
pipeline {
  agent any
  options {
    buildDiscarder(logRotator(daysToKeepStr: '[1]'))
  }
  stages {
    stage('Example') {
      steps {
        echo 'Hello World'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A30
B10
C60
D90
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number
Setting days to 0 which disables retention
2fill in blank
medium

Complete the code to rotate logs based on the number of builds to keep.

Jenkins
pipeline {
  agent any
  options {
    buildDiscarder(logRotator(numToKeepStr: '[1]'))
  }
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A20
B5
C10
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using a very high number causing disk space issues
Using zero which disables retention
3fill in blank
hard

Fix the error in the log rotation configuration to correctly discard old builds.

Jenkins
pipeline {
  agent any
  options {
    buildDiscarder(logRotator(numToKeepStr: '[1]', daysToKeepStr: '15'))
  }
  stages {
    stage('Test') {
      steps {
        echo 'Testing...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A-5
B0
C10
Dabc
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero disables retention
Using negative numbers causes errors
Using non-numeric strings causes syntax errors
4fill in blank
hard

Fill both blanks to configure Jenkins to keep 7 days of logs and 3 builds.

Jenkins
pipeline {
  agent any
  options {
    buildDiscarder(logRotator(daysToKeepStr: '[1]', numToKeepStr: '[2]'))
  }
  stages {
    stage('Deploy') {
      steps {
        echo 'Deploying...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A7
B3
C14
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the values between days and builds
Using zero or negative numbers
5fill in blank
hard

Fill all three blanks to configure Jenkins to keep logs for 14 days, 10 builds, and disable artifact retention.

Jenkins
pipeline {
  agent any
  options {
    buildDiscarder(logRotator(daysToKeepStr: '[1]', numToKeepStr: '[2]', artifactDaysToKeepStr: '[3]'))
  }
  stages {
    stage('Package') {
      steps {
        echo 'Packaging...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
A14
B10
C0
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-numeric values
Setting artifactDaysToKeepStr to a positive number when disabling is intended

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