Artifacts & post actions

Archive results; act on success or failure.

Beginner10 min · lesson 10 of 15

A build usually produces something worth keeping — a compiled binary, a jar, a coverage report, a packaged image. Archiving artifacts attaches those files to the build record so you can download exactly what a given build produced, weeks later, without rebuilding. It is the difference between "we think build 412 shipped this" and "here is the precise binary build 412 made."

Jenkinsfile
stage('Package') {
steps { sh 'make dist' }
post {
success {
archiveArtifacts artifacts: 'dist/**', fingerprint: true
// fingerprint records a hash so you can trace this exact file across jobs
}
}
}

Artifacts vs a real registry

Jenkins artifact archiving is for build outputs you want attached to the build for convenience and traceability. It is not a distribution system — container images belong in a container registry, packages in an artifact repository (Artifactory, Nexus). The pattern is: build the image, push it to the registry (tagged with the build/commit), and archive only the small stuff (reports, manifests) in Jenkins.

post conditions do the housekeeping

The post block is where you wire outcome-driven actions: archive on success, capture logs and notify on failure, and always clean the workspace so the next build starts fresh. Because these run based on the build result, your pipeline behaves sensibly whether it passed or failed — results are saved, people are told, and disk is reclaimed, without you thinking about it each time.

Jenkinsfile
post {
success { archiveArtifacts 'dist/**' }
failure {
archiveArtifacts artifacts: 'logs/**', allowEmptyArchive: true
slackSend channel: '#builds', message: "FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER}"
}
cleanup { cleanWs() }
}
Do not archive huge trees or secrets
Archiving node_modules or a whole build tree fills the controller’s disk fast (artifacts live in JENKINS_HOME on the controller). Archive only what you need — the built binary, reports — and never archive files that contain credentials or a .env; archived artifacts are downloadable by anyone who can see the build.