Bird
Raised Fist0
Jenkinsdevops~20 mins

Artifact retention policies in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Artifact Retention Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding artifact retention in Jenkins

What is the primary purpose of setting artifact retention policies in Jenkins?

ATo automatically delete old build artifacts to save disk space
BTo speed up the build process by caching artifacts
CTo increase the number of builds stored indefinitely
DTo prevent any build artifacts from being deleted
Attempts:
2 left
💡 Hint

Think about why disk space might be limited on build servers.

💻 Command Output
intermediate
2:00remaining
Effect of artifact retention configuration in Jenkinsfile

Given the following Jenkinsfile snippet, what will be the number of builds with artifacts retained after 10 builds?

Jenkins
pipeline {
  agent any
  options {
    buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '3'))
  }
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
}
ANo builds will have artifacts retained
B5 builds will have artifacts retained
CAll 10 builds will have artifacts retained
D3 builds will have artifacts retained
Attempts:
2 left
💡 Hint

Look at the artifactNumToKeepStr value.

❓ Configuration
advanced
2:00remaining
Configuring artifact retention via Jenkins UI

Which configuration in Jenkins UI correctly sets artifact retention to keep artifacts for the last 7 builds only?

AIn the job configuration, under 'Build Environment', enable 'Discard old builds' and set 'Max # of artifacts to keep' to 7
BIn the job configuration, under 'Discard old builds', set 'Max # of builds to keep' to 7 and 'Max # of artifacts to keep' to 7
CIn the job configuration, under 'Discard old builds', set 'Max # of builds to keep' to 7 and leave 'Max # of artifacts to keep' empty
DIn the job configuration, under 'Build Triggers', enable 'Discard old builds' and set 'Max # of builds to keep' to 7
Attempts:
2 left
💡 Hint

Artifact retention requires both builds and artifacts limits to be set.

❓ Troubleshoot
advanced
2:00remaining
Troubleshooting artifact retention not working

A Jenkins job is configured to discard old builds and artifacts, but artifacts are not being deleted as expected. What is the most likely cause?

AThe Jenkins master has insufficient disk space
BThe artifacts are stored on a network share that Jenkins cannot access
CThe job is using a pipeline script without a <code>buildDiscarder</code> option configured
DThe job has no post-build actions configured
Attempts:
2 left
💡 Hint

Retention settings in pipeline scripts require explicit configuration.

✅ Best Practice
expert
2:30remaining
Best practice for artifact retention in large Jenkins environments

In a large Jenkins environment with many jobs producing large artifacts, what is the best practice to manage artifact retention efficiently?

AUse centralized artifact storage with lifecycle policies and configure Jenkins to discard local artifacts quickly
BKeep all artifacts indefinitely on Jenkins master to avoid losing any data
CDisable artifact retention and manually delete artifacts weekly
DConfigure each job to keep artifacts for at least 100 builds to ensure availability
Attempts:
2 left
💡 Hint

Think about scalability and automation in managing storage.

Practice

(1/5)
1. What is the main purpose of artifact retention policies in Jenkins?
easy
A. To manage disk space by deleting old build files
B. To speed up the build process by caching dependencies
C. To increase the number of builds stored indefinitely
D. To automatically trigger builds on code changes

Solution

  1. Step 1: Understand artifact retention policies

    Artifact retention policies control how long build files are kept to avoid using too much disk space.
  2. Step 2: Identify the main goal

    The main goal is to delete old build files to free up disk space.
  3. Final Answer:

    To manage disk space by deleting old build files -> Option A
  4. Quick Check:

    Artifact retention = disk space management [OK]
Hint: Retention policies delete old builds to save space [OK]
Common Mistakes:
  • Confusing retention with build triggering
  • Thinking retention speeds up builds
  • Assuming retention keeps all builds forever
2. Which Jenkins pipeline syntax correctly sets a retention policy to keep only the last 5 builds?
easy
A. archiveArtifacts(numToKeepStr: '5')
B. buildDiscarder(keepLast: 5)
C. buildDiscarder(logRotator(numToKeepStr: '5'))
D. archiveArtifacts(logRotator(numToKeepStr: '5'))

Solution

  1. Step 1: Identify correct syntax for retention

    Retention uses buildDiscarder with logRotator to specify how many builds to keep.
  2. Step 2: Check option correctness

    buildDiscarder(logRotator(numToKeepStr: '5')) uses correct syntax: buildDiscarder(logRotator(numToKeepStr: '5')). Others misuse archiveArtifacts or wrong parameters.
  3. Final Answer:

    buildDiscarder(logRotator(numToKeepStr: '5')) -> Option C
  4. Quick Check:

    Retention uses buildDiscarder + logRotator [OK]
Hint: Retention = buildDiscarder with logRotator [OK]
Common Mistakes:
  • Using archiveArtifacts to set retention
  • Wrong parameter names like keepLast
  • Nesting logRotator inside archiveArtifacts
3. Given this Jenkins pipeline snippet:
pipeline {
  options {
    buildDiscarder(logRotator(numToKeepStr: '3', daysToKeepStr: '7'))
  }
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
}
What happens to builds older than 7 days or beyond the last 3 builds?
medium
A. They are deleted to free disk space
B. They are archived permanently
C. They trigger a new build automatically
D. They are kept indefinitely

Solution

  1. Step 1: Understand logRotator parameters

    It keeps only the last 3 builds and deletes builds older than 7 days.
  2. Step 2: Determine effect on old builds

    Builds older than 7 days or beyond the last 3 are deleted to save space.
  3. Final Answer:

    They are deleted to free disk space -> Option A
  4. Quick Check:

    logRotator deletes old builds [OK]
Hint: logRotator deletes builds older than days or count [OK]
Common Mistakes:
  • Thinking builds are archived permanently
  • Assuming builds trigger new builds
  • Believing builds are kept forever
4. You wrote this Jenkins pipeline snippet to keep artifacts for 10 days:
options {
  buildDiscarder(logRotator(artifactDaysToKeep: '10'))
}
But artifacts are not deleted after 10 days. What is the likely problem?
medium
A. logRotator does not support artifact retention
B. The buildDiscarder option must be inside stages
C. You must use archiveArtifacts to delete old artifacts
D. The parameter name should be artifactDaysToKeepStr, not artifactDaysToKeep

Solution

  1. Step 1: Check logRotator parameter names

    logRotator parameters for strings end with 'Str', like artifactDaysToKeepStr.
  2. Step 2: Identify the syntax issue

    Missing 'Str' means the parameter is not recognized, so default retention applies and artifacts aren't deleted after 10 days.
  3. Final Answer:

    The parameter name should be artifactDaysToKeepStr, not artifactDaysToKeep -> Option D
  4. Quick Check:

    logRotator params end with 'Str' [OK]
Hint: logRotator params like artifactDaysToKeepStr end with Str [OK]
Common Mistakes:
  • Using wrong parameter names
  • Expecting logRotator to delete artifacts
  • Placing buildDiscarder outside options block
5. You want to keep artifacts only for the last 4 builds and delete older artifacts automatically, while keeping older builds. Which Jenkins pipeline snippet correctly applies this retention policy?
hard
A. steps { archiveArtifacts artifacts: '**/*', onlyIfSuccessful: true, retentionDays: 4 }
B. options { buildDiscarder(logRotator(artifactNumToKeepStr: '4')) }
C. options { buildDiscarder(logRotator(numToKeepStr: '4')) } steps { archiveArtifacts artifacts: '**/*', onlyIfSuccessful: true }
D. steps { archiveArtifacts artifacts: '**/*', keepOnlyLast: 4 }

Solution

  1. Step 1: Understand roles for artifact-specific retention

    To keep artifacts from only the last 4 builds while retaining builds, use artifactNumToKeepStr.
  2. Step 2: Check option correctness

    options { buildDiscarder(logRotator(artifactNumToKeepStr: '4')) }: buildDiscarder(logRotator(artifactNumToKeepStr: '4')) keeps artifacts from last 4 builds, deletes older artifacts, keeps all builds. C deletes old builds too. B/D use invalid params.
  3. Final Answer:

    options { buildDiscarder(logRotator(artifactNumToKeepStr: '4')) } -> Option B
  4. Quick Check:

    artifactNumToKeepStr for artifacts only [OK]
Hint: artifactNumToKeepStr keeps artifacts from last N builds [OK]
Common Mistakes:
  • Using invalid parameters like retentionDays or keepOnlyLast
  • Trying to control retention only via archiveArtifacts
  • Misplacing buildDiscarder outside options block
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