How to Archive Build Artifacts in a Jenkins Pipeline
archiveArtifacts attaches matched files to the build so they are downloadable later from the build page.
Point archiveArtifacts at a glob of your build outputs. Add fingerprinting to track which build produced an artifact across jobs.
Archive with fingerprinting
Archive the dist bundle and fingerprint it so Jenkins can trace it across jobs.
pipeline {
agent any
stages {
stage('Build') {
steps { sh 'npm ci && npm run build' }
}
}
post {
success {
archiveArtifacts artifacts: 'dist/**/*', fingerprint: true
}
}
}Notes
- fingerprint: true lets Jenkins correlate the same artifact across upstream and downstream builds.
- Archived artifacts live with the build record; configure build retention to bound disk usage.
- For large binaries prefer an external store and archive only a manifest.
Verify it actually works
Validate the pipeline definition against the running controller before committing. Jenkins parses declarative pipelines strictly, and a syntax error surfaces as a failed build rather than a clear parse message.
# validate a Jenkinsfile against the live controller
curl -X POST -F "jenkinsfile=<Jenkinsfile" \
https://your-jenkins/pipeline-model-converter/validate
# replay a build with modified script to test a change without committing
# Build page -> Replay -> edit -> RunAgent and workspace assumptions that break in CI
- An agent label that matches no online agent leaves the build queued indefinitely rather than failing.
- Workspaces are reused between builds by default, so stale files from a previous run can mask or cause failures. Use
cleanWs()or a fresh workspace when correctness matters. - Tools resolved from the controller PATH are not necessarily on the agent PATH. Declare them in a
toolsblock or install them in the pipeline. - Credentials bound with
withCredentialsare masked in logs but still visible to any process you launch; avoid passing them as command-line arguments.