0
0
Jenkinsdevops~5 mins

Artifact fingerprinting in Jenkins - Commands & Configuration

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