0
0
Jenkinsdevops~10 mins

Log management and rotation in Jenkins - Interactive Code Practice

Choose your learning style9 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