Artifact fingerprinting in Jenkins - Time & Space Complexity
We want to understand how the time needed to fingerprint artifacts grows as we handle more files.
How does the process scale when the number of artifacts increases?
Analyze the time complexity of the following code snippet.
pipeline {
agent any
stages {
stage('Fingerprint Artifacts') {
steps {
fingerprint '**/*.jar'
}
}
}
}
This pipeline fingerprints all jar files found in the workspace to track their usage.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Scanning and fingerprinting each matching artifact file.
- How many times: Once for each jar file found in the workspace.
As the number of jar files increases, the fingerprinting work grows proportionally.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 fingerprint operations |
| 100 | 100 fingerprint operations |
| 1000 | 1000 fingerprint operations |
Pattern observation: The time grows directly with the number of files; doubling files doubles work.
Time Complexity: O(n)
This means the time to fingerprint grows in a straight line with the number of artifacts.
[X] Wrong: "Fingerprinting all files takes the same time no matter how many files there are."
[OK] Correct: Each file must be processed separately, so more files mean more time.
Understanding how fingerprinting scales helps you explain build pipeline performance clearly and confidently.
"What if we fingerprinted only changed files instead of all files? How would the time complexity change?"
Practice
Solution
Step 1: Understand artifact fingerprinting concept
Artifact fingerprinting is used to track files uniquely across Jenkins builds.Step 2: Identify the main purpose
Its main purpose is to know where files come from and where they are used, not speeding builds or deployment.Final Answer:
To uniquely track files across different builds -> Option AQuick Check:
Artifact fingerprinting = Unique file tracking [OK]
- Confusing fingerprinting with deployment
- Thinking it speeds up builds
- Assuming it backs up logs
Solution
Step 1: Recall Jenkins pipeline steps for artifacts
Common steps include archiveArtifacts, stash, fingerprint, and publish.Step 2: Identify the step for fingerprinting
Thefingerprintstep is specifically used to enable artifact fingerprinting on files.Final Answer:
fingerprint 'file.txt' -> Option DQuick Check:
Use fingerprint step to track files [OK]
- Using archiveArtifacts instead of fingerprint
- Confusing stash with fingerprint
- Using publish which is unrelated
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'echo Hello > output.txt'
fingerprint 'output.txt'
}
}
}
}What does the
fingerprint 'output.txt' step do here?Solution
Step 1: Analyze the pipeline snippet
The pipeline creates a file output.txt and then fingerprints it.Step 2: Understand fingerprint step effect
The fingerprint step creates a unique hash for the file to track it across builds, not deleting or copying it.Final Answer:
Creates a unique hash for output.txt to track it across builds -> Option BQuick Check:
Fingerprint = unique hash tracking [OK]
- Thinking fingerprint deletes files
- Assuming it copies files
- Confusing fingerprint with upload
fingerprint 'app.jar' in your Jenkins pipeline, but fingerprints are not generated. What is a likely cause?Solution
Step 1: Check file existence for fingerprinting
Fingerprinting requires the file to exist at the specified path during the build.Step 2: Identify common causes for no fingerprints
If the file path is wrong or file missing, fingerprinting won't generate fingerprints.Final Answer:
The file path 'app.jar' is incorrect or file does not exist -> Option CQuick Check:
File must exist for fingerprinting [OK]
- Assuming fingerprint needs extra plugin
- Thinking archiveArtifacts is mandatory before fingerprint
- Believing fingerprint only works on text files
Solution
Step 1: Understand tracking multiple artifacts
To track multiple files, fingerprinting should be applied to all relevant files, e.g., using a pattern.Step 2: Evaluate options for multiple files
Usingfingerprint '**/*.jar'fingerprints all jar files, enabling tracking across builds.Final Answer:
Use fingerprint '**/*.jar' after building all jar files -> Option AQuick Check:
Fingerprint all files with pattern for tracking [OK]
- Fingerprinting only one file when multiple exist
- Confusing stash with fingerprinting
- Skipping fingerprinting in later builds
Ready to prove it?
Pass the test and this pattern moves unknown
