Bird
Raised Fist0
Jenkinsdevops~20 mins

Archiving artifacts in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Artifact Archiver Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Jenkins pipeline snippet?
Consider this Jenkins pipeline step for archiving artifacts:
archiveArtifacts artifacts: '**/build/*.jar', fingerprint: true

What does this step do when executed?
Jenkins
archiveArtifacts artifacts: '**/build/*.jar', fingerprint: true
ADeletes all .jar files inside any 'build' folder in the workspace after the build.
BCopies .jar files from the workspace to a remote server without fingerprinting.
CArchives all .jar files inside any 'build' folder in the workspace and records fingerprints for tracking.
DArchives only the first .jar file found in the root workspace directory.
Attempts:
2 left
💡 Hint
Think about what 'archiveArtifacts' and 'fingerprint: true' mean in Jenkins.
❓ Configuration
intermediate
2:00remaining
Which Jenkinsfile snippet correctly archives all .log files from the 'logs' directory?
You want to archive all .log files located directly inside the 'logs' folder in your workspace. Which snippet achieves this?
AarchiveArtifacts artifacts: '**/logs/*.log'
BarchiveArtifacts artifacts: '*.log'
CarchiveArtifacts artifacts: 'logs/**/*.log'
DarchiveArtifacts artifacts: 'logs/*.log'
Attempts:
2 left
💡 Hint
Remember how glob patterns match files in directories.
❓ Troubleshoot
advanced
2:00remaining
Why does the archiveArtifacts step fail with 'No artifacts found'?
You have this Jenkins pipeline step:
archiveArtifacts artifacts: 'target/*.war'

But the build fails with 'No artifacts found' error. What is the most likely cause?
AThe Jenkins agent does not have permission to write to the workspace.
BThe 'target' directory does not exist or contains no .war files at archive time.
CThe 'archiveArtifacts' step requires a full absolute path, not a relative one.
DThe pipeline syntax is incorrect; 'artifacts' should be 'artifact'.
Attempts:
2 left
💡 Hint
Check if the files exist at the time the step runs.
🔀 Workflow
advanced
2:00remaining
In which stage should you place the archiveArtifacts step for best practice?
You have a Jenkins pipeline with stages: Build, Test, and Deploy. Where should you place the archiveArtifacts step to archive build outputs?
AImmediately after the Build stage completes successfully.
BAt the start of the Test stage before tests run.
CAfter the Deploy stage to archive deployed files.
DBefore the Build stage to archive previous artifacts.
Attempts:
2 left
💡 Hint
Think about when build outputs are ready and stable.
✅ Best Practice
expert
2:00remaining
What is the main benefit of enabling fingerprinting when archiving artifacts in Jenkins?
You enable fingerprinting in the archiveArtifacts step like this:
archiveArtifacts artifacts: 'dist/*.zip', fingerprint: true

What is the primary benefit of this fingerprinting?
AIt tracks which builds produced or used the same artifact files for traceability.
BIt compresses the artifacts to save storage space on the Jenkins server.
CIt automatically uploads artifacts to an external artifact repository.
DIt encrypts the artifacts to secure them from unauthorized access.
Attempts:
2 left
💡 Hint
Fingerprinting is about tracking, not compression or encryption.

Practice

(1/5)
1. What is the main purpose of using archiveArtifacts in a Jenkins pipeline?
easy
A. To delete old build files automatically
B. To save build output files for later use or sharing
C. To trigger another build job
D. To send email notifications after a build

Solution

  1. Step 1: Understand the role of archiveArtifacts

    This command is used to save files generated by a build so they can be accessed later.
  2. Step 2: Compare with other options

    Deleting files, triggering builds, or sending emails are different Jenkins features, not related to archiving artifacts.
  3. Final Answer:

    To save build output files for later use or sharing -> Option B
  4. Quick Check:

    Archiving = Saving build files [OK]
Hint: Archiving means saving build files for future use [OK]
Common Mistakes:
  • Confusing archiving with deleting files
  • Thinking it triggers other jobs
  • Assuming it sends notifications
2. Which of the following is the correct syntax to archive all .jar files in a Jenkins pipeline script?
easy
A. archiveArtifacts '*.jar'
B. archiveArtifacts '*.jar;'
C. archiveArtifacts '*.jar' {}
D. archiveArtifacts '*.jar'()

Solution

  1. Step 1: Recall the syntax of archiveArtifacts

    The correct syntax uses the command followed by the file pattern in quotes without extra characters.
  2. Step 2: Identify incorrect syntax

    Options with semicolon, braces, or parentheses after the pattern are invalid in Jenkins pipeline syntax.
  3. Final Answer:

    archiveArtifacts '*.jar' -> Option A
  4. Quick Check:

    Correct syntax = archiveArtifacts 'pattern' [OK]
Hint: Use single quotes and no extra symbols after pattern [OK]
Common Mistakes:
  • Adding semicolons inside the pattern string
  • Using braces or parentheses incorrectly
  • Missing quotes around the pattern
3. Given this Jenkins pipeline snippet:
stage('Build') {
  steps {
    sh 'echo Hello > output.txt'
    archiveArtifacts 'output.txt'
  }
}

What will Jenkins do after this stage completes?
medium
A. Send output.txt as an email attachment
B. Delete the file output.txt immediately
C. Fail the build because output.txt is not found
D. Save the file output.txt as a build artifact

Solution

  1. Step 1: Understand the shell command

    The command creates a file named output.txt with the text 'Hello'.
  2. Step 2: Analyze archiveArtifacts usage

    This command archives the specified file so it is saved with the build for later access.
  3. Final Answer:

    Save the file output.txt as a build artifact -> Option D
  4. Quick Check:

    archiveArtifacts saves files [OK]
Hint: archiveArtifacts saves files created in the build [OK]
Common Mistakes:
  • Assuming the file is deleted after archiving
  • Thinking the build fails if file exists
  • Confusing archiving with emailing files
4. You wrote this Jenkins pipeline snippet:
archiveArtifacts '*.log'

But no files are archived after the build. What is the most likely reason?
medium
A. No .log files were created in the workspace
B. The syntax of archiveArtifacts is incorrect
C. Jenkins does not support archiving .log files
D. The build failed before reaching the archive step

Solution

  1. Step 1: Check the file pattern and workspace

    If no .log files exist in the workspace, nothing will be archived.
  2. Step 2: Verify syntax and Jenkins support

    The syntax is correct and Jenkins supports archiving any file type.
  3. Step 3: Consider build status

    If the build failed before this step, archiving wouldn't run, but the question implies the step ran.
  4. Final Answer:

    No .log files were created in the workspace -> Option A
  5. Quick Check:

    Files must exist to be archived [OK]
Hint: Check if files exist before archiving [OK]
Common Mistakes:
  • Assuming Jenkins can't archive certain file types
  • Blaming syntax without checking files
  • Ignoring build step execution order
5. You want to archive all .jar files in the build/libs folder and also keep the build logs named build.log. Which archiveArtifacts usage is correct?
hard
A. archiveArtifacts 'build/libs/*.jar', build.log
B. archiveArtifacts 'build/libs/*.jar build.log'
C. archiveArtifacts artifacts: 'build/libs/*.jar, build.log'
D. archiveArtifacts artifacts: 'build/libs/*.jar', 'build.log'

Solution

  1. Step 1: Understand multiple file patterns in archiveArtifacts

    To archive multiple patterns, use the named parameter artifacts with a comma-separated string.
  2. Step 2: Analyze each option

    archiveArtifacts 'build/libs/*.jar', build.log passes two positional arguments (invalid), archiveArtifacts 'build/libs/*.jar build.log' lacks comma separator, archiveArtifacts artifacts: 'build/libs/*.jar', 'build.log' has invalid syntax with two strings.
  3. Final Answer:

    archiveArtifacts artifacts: 'build/libs/*.jar, build.log' -> Option C
  4. Quick Check:

    Use artifacts: 'pattern1, pattern2' for multiple files [OK]
Hint: Use artifacts: 'pattern1, pattern2' to archive multiple files [OK]
Common Mistakes:
  • Omitting the artifacts: parameter
  • Separating patterns without commas
  • Passing multiple strings instead of one
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