Bird
Raised Fist0
Jenkinsdevops~5 mins

Artifact fingerprinting in Jenkins - Commands & Configuration

Choose your learning style10 modes available
Introduction
When you build software, you create files called artifacts. Artifact fingerprinting helps track these files across different builds and jobs to know exactly which build produced which artifact. This avoids confusion and helps manage dependencies clearly.
When you want to know which build created a specific artifact file.
When multiple jobs share or use the same artifact and you want to track its origin.
When you want to avoid rebuilding artifacts unnecessarily by reusing existing ones.
When you want to trace the history of an artifact through your Jenkins pipeline.
When you want to ensure artifact integrity and avoid mixing different versions.
Config File - Jenkinsfile
Jenkinsfile
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        sh 'echo "Hello World" > output.txt'
        archiveArtifacts artifacts: 'output.txt', fingerprint: true
      }
    }
    stage('Use Artifact') {
      steps {
        fingerprint 'output.txt'
        echo 'Artifact fingerprint recorded and tracked'
      }
    }
  }
}

This Jenkinsfile defines a simple pipeline with two stages.

In the 'Build' stage, it creates a file named output.txt and archives it with fingerprinting enabled. This means Jenkins will track this file's unique fingerprint.

In the 'Use Artifact' stage, it explicitly fingerprints the same file to link it to the build and track usage.

Commands
This command updates the Jenkins job configuration with the pipeline that includes artifact fingerprinting.
Terminal
jenkins-jobs --conf jenkins.ini update my-pipeline.yaml
Expected OutputExpected
Job 'my-pipeline' updated successfully
→
--conf - Specifies the Jenkins configuration file to use
This triggers a build of the Jenkins pipeline to generate and fingerprint the artifact.
Terminal
curl -X POST http://localhost:8080/job/my-pipeline/build --user admin:admin123
Expected OutputExpected
No output (command runs silently)
This fetches the details of the last build, including fingerprint information for artifacts.
Terminal
curl http://localhost:8080/job/my-pipeline/lastBuild/api/json --user admin:admin123
Expected OutputExpected
{"artifacts":[{"fileName":"output.txt","relativePath":"output.txt"}],"fingerprints":[{"hash":"d41d8cd98f00b204e9800998ecf8427e","original":{"name":"output.txt"}}]}
This command retrieves detailed fingerprint information about the artifact, showing which builds used it.
Terminal
curl http://localhost:8080/fingerprint/d41d8cd98f00b204e9800998ecf8427e/api/json --user admin:admin123
Expected OutputExpected
{"hash":"d41d8cd98f00b204e9800998ecf8427e","fileName":"output.txt","usage":[{"jobName":"my-pipeline","buildNumber":1}]}
Key Concept

If you remember nothing else from artifact fingerprinting, remember: it uniquely identifies and tracks files across builds to manage dependencies and history clearly.

Common Mistakes
Not enabling fingerprinting when archiving artifacts.
Without fingerprinting, Jenkins cannot track the artifact's origin or usage.
Always set fingerprint: true in archiveArtifacts step to enable tracking.
Fingerprinting files that are not archived or do not exist.
Fingerprinting a missing or unarchived file causes errors or no tracking.
Ensure the file exists and is archived before fingerprinting it.
Not checking fingerprint details after build to verify tracking.
You might miss if fingerprinting failed or artifacts are not tracked properly.
Use Jenkins API or UI to verify fingerprint data after builds.
Summary
Use archiveArtifacts with fingerprint: true to track artifact files in Jenkins builds.
Trigger builds to generate and fingerprint artifacts automatically.
Check fingerprint data via Jenkins API to see artifact usage and origin.

Practice

(1/5)
1. What is the main purpose of artifact fingerprinting in Jenkins?
easy
A. To uniquely track files across different builds
B. To speed up the build process
C. To automatically deploy artifacts to servers
D. To create backups of build logs

Solution

  1. Step 1: Understand artifact fingerprinting concept

    Artifact fingerprinting is used to track files uniquely across Jenkins builds.
  2. 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.
  3. Final Answer:

    To uniquely track files across different builds -> Option A
  4. Quick Check:

    Artifact fingerprinting = Unique file tracking [OK]
Hint: Fingerprinting tracks files uniquely across builds [OK]
Common Mistakes:
  • Confusing fingerprinting with deployment
  • Thinking it speeds up builds
  • Assuming it backs up logs
2. Which Jenkins pipeline step is used to enable artifact fingerprinting for a file?
easy
A. archiveArtifacts 'file.txt'
B. publish 'file.txt'
C. stash 'file.txt'
D. fingerprint 'file.txt'

Solution

  1. Step 1: Recall Jenkins pipeline steps for artifacts

    Common steps include archiveArtifacts, stash, fingerprint, and publish.
  2. Step 2: Identify the step for fingerprinting

    The fingerprint step is specifically used to enable artifact fingerprinting on files.
  3. Final Answer:

    fingerprint 'file.txt' -> Option D
  4. Quick Check:

    Use fingerprint step to track files [OK]
Hint: Use fingerprint step with file path to track [OK]
Common Mistakes:
  • Using archiveArtifacts instead of fingerprint
  • Confusing stash with fingerprint
  • Using publish which is unrelated
3. Given this Jenkins pipeline snippet:
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        sh 'echo Hello > output.txt'
        fingerprint 'output.txt'
      }
    }
  }
}

What does the fingerprint 'output.txt' step do here?
medium
A. Deletes output.txt after the build
B. Creates a unique hash for output.txt to track it across builds
C. Copies output.txt to the workspace
D. Uploads output.txt to a remote server

Solution

  1. Step 1: Analyze the pipeline snippet

    The pipeline creates a file output.txt and then fingerprints it.
  2. 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.
  3. Final Answer:

    Creates a unique hash for output.txt to track it across builds -> Option B
  4. Quick Check:

    Fingerprint = unique hash tracking [OK]
Hint: Fingerprint creates unique hash for file tracking [OK]
Common Mistakes:
  • Thinking fingerprint deletes files
  • Assuming it copies files
  • Confusing fingerprint with upload
4. You added fingerprint 'app.jar' in your Jenkins pipeline, but fingerprints are not generated. What is a likely cause?
medium
A. You must archive artifacts before fingerprinting
B. Fingerprinting requires a separate plugin installation
C. The file path 'app.jar' is incorrect or file does not exist
D. Fingerprinting only works on text files

Solution

  1. Step 1: Check file existence for fingerprinting

    Fingerprinting requires the file to exist at the specified path during the build.
  2. Step 2: Identify common causes for no fingerprints

    If the file path is wrong or file missing, fingerprinting won't generate fingerprints.
  3. Final Answer:

    The file path 'app.jar' is incorrect or file does not exist -> Option C
  4. Quick Check:

    File must exist for fingerprinting [OK]
Hint: Ensure file exists at path before fingerprinting [OK]
Common Mistakes:
  • Assuming fingerprint needs extra plugin
  • Thinking archiveArtifacts is mandatory before fingerprint
  • Believing fingerprint only works on text files
5. In a Jenkins pipeline, you want to track multiple artifacts and find all builds that used them. Which approach correctly uses artifact fingerprinting for this?
hard
A. Use fingerprint '**/*.jar' after building all jar files
B. Archive artifacts first, then fingerprint only one file manually
C. Use stash for all files and fingerprint none
D. Fingerprint files only in the first build, skip others

Solution

  1. Step 1: Understand tracking multiple artifacts

    To track multiple files, fingerprinting should be applied to all relevant files, e.g., using a pattern.
  2. Step 2: Evaluate options for multiple files

    Using fingerprint '**/*.jar' fingerprints all jar files, enabling tracking across builds.
  3. Final Answer:

    Use fingerprint '**/*.jar' after building all jar files -> Option A
  4. Quick Check:

    Fingerprint all files with pattern for tracking [OK]
Hint: Fingerprint all files with a pattern to track multiple artifacts [OK]
Common Mistakes:
  • Fingerprinting only one file when multiple exist
  • Confusing stash with fingerprinting
  • Skipping fingerprinting in later builds
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