Archiving Artifacts
Archive build outputs like binaries, packages, or reports so you can download them from any build.
Syntax
archiveArtifacts artifacts: 'build/*.jar', fingerprint: trueArtifacts are the files your build produces — a compiled JAR, a Docker image tarball, a coverage report. The archiveArtifacts step saves them to Jenkins so they are downloadable long after the workspace is cleaned.
Why archive?
- Download a specific build's output later.
- Keep reports (coverage, logs) attached to each build.
- Pass files between jobs.
Patterns
Use Ant-style glob patterns like build/**/*.jar or dist/*.zip to select files.
Example
pipeline {
agent any
stages {
stage('Package') {
steps {
sh 'npm run build'
sh 'tar -czf dist.tar.gz dist/'
}
}
}
post {
success {
archiveArtifacts artifacts: 'dist.tar.gz', fingerprint: true
}
}
}When to use it
- A Maven pipeline archives the built JAR so testers can download it from the build page without re-running the build.
- A Docker-less environment archives a tarball of the compiled frontend so downstream jobs can deploy it directly.
- A release pipeline archives both the binary and the SHA-256 checksum file so the release can be verified after download.
More examples
Archive JAR artifact
Archives the Maven JAR and fingerprints it so Jenkins can trace which build produced the file.
post {
success {
archiveArtifacts artifacts: 'target/*.jar',
fingerprint: true,
onlyIfSuccessful: true
}
}Stash and unstash between stages
Stashes the compiled frontend from the build agent and unstashes it on a different deploy agent.
stage('Build') {
steps {
sh 'npm run build'
stash name: 'dist', includes: 'dist/**'
}
}
stage('Deploy') {
agent { label 'deploy-agent' }
steps {
unstash 'dist'
sh 'rsync -av dist/ deploy@prod:/var/www/html/'
}
}Archive multiple artifact patterns
Archives multiple artifact types matching different glob patterns in a single archiveArtifacts call.
post {
always {
archiveArtifacts artifacts: [
'dist/**/*.js',
'reports/**/*.html',
'target/*.jar'
].join(', '),
allowEmptyArchive: true
}
}
Discussion