Contents

Jenkins Artifacts and Fingerprint

Basic explanation on Jenkins Artifacts and Fingerprint

Website Visitors:

Do you know, with Jenkins you can retrieve an output from Jenkins and use it in other pipeline jobs. In this tutorial, we will explain about the same - Jenkins Artifacts and Fingerprint.

Jenkins Artifacts

When Jenkins job creates an object that need to be saved, that object is called artifact. Artifacts can be any binary files or zip files or any reports. Archive artifacts are placed in the post {} section in the Jenkins code pipeline. This post block runs at the last in the pipeline. There is also a copy artifact plugin, which provides a build step in the pipeline. It can pull artifacts from other jobs. It can also set permissions to copy artifacts.

Jenkins Finterprinting

When artifact is created or used, Jenkins generates md5 checksum using the artifact. This checksum and the job that was created are tracked in internal database. This becomes the file fingerprint. Jenkins uses this fingerprint to find what jobs are created or accessed the file.

Example pipeline script

To get a better understanding of Jenkins Artifacts and reading artifacts from other pipeline scripts, checkout the below sample script. This script creates an artifact called report.txt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
pipeline {
    agent any
    stages {
        stage('Create Artifact') {
            steps {
                sh "set > report.txt"
            }
        }
    }
    post {
        always {
            archiveArtifacts artifacts: 'report.txt', 
            fingerprint: true, 
            followSymlinks: false
        }
    }
}

After the above pipeline script is executed, go to the build details. You will find See Fingerprints option. Click it and click on the artifact name. It will show the MD5 checksum value.

Reading Artifact script

This below script reads the artifact created from above script called report.txt and copies it to /tmp folder on the Jenkins node.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
pipeline {
    agent any
    stages {
        stage('Read-Archive') {
            steps {
                copyArtifacts filter: 'report.txt', 
                fingerprintArtifacts: true, 
                // In below project name, Artifact and Fingerprint is the name of above script which creates the artifact 
                projectName: 'Artifact and Fingerprint', 
                target: '/tmp/'
            }
        }
    }
}

Suggested Article

Now that you know about Jenkins Artifacts and Fingerprint, continue reading our other article Jenkins conditions and confirmations here. All other DevOps categories are listed here: DevOps Tools. Have a look at the posts as per your topic of interest.

Conclusion

In this tutorial, we’ve explained what is Jenkins Artifacts and Fingerprint. We’ve also demonstrated examples for all the topics that are discussed.

Please feel free to share your thoughts about this tutorial in the comments section below.

Your inbox needs more DevOps articles.

Subscribe to get our latest content by email.