Artifacts and Versioning in Jenkins: archiveArtifacts, Nexus and Artifactory, Semantic Versions and Release Builds

CI CD Pipelines with Jenkins 35 min min read Updated: Nov 17, 2026 Intermediate
Artifacts and Versioning in Jenkins: archiveArtifacts, Nexus and Artifactory, Semantic Versions and Release Builds
Intermediate Topic 3 of 3

Build Once, Promote the Same Artifact

The most important release rule: build the artifact once, test it, and then move that exact file or image through staging and production. If you rebuild for production you ship something nobody tested.

text source ─► BUILD ONCE ─► artifact v1.4.2+3f9c2ab ─► test ─► staging ─► approval ─► production (same bytes, same checksum, same image digest)

Jenkins' Own Artifact Storage

groovy archiveArtifacts artifacts: 'target/*.jar, target/*.war', fingerprint: true, onlyIfSuccessful: true // In another job: copyArtifacts projectName: 'shop-build', selector: lastSuccessful(), filter: 'target/*.jar' // Copy Artifact plugi
  • Artifacts are stored in JENKINS_HOME on the controller. They are fine for small files and short retention
  • Fingerprints record the MD5 of a file so Jenkins can show where it was built and used
  • Large or long-lived artifacts belong in a repository manager or object storage
  • Limit retention: buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '5'))

Artifact Repositories

ToolStoresNotes
Sonatype Nexus RepositoryMaven, npm, PyPI, Docker, NuGet, Helm, raw filesHosted, proxy (cache) and group repositories
JFrog ArtifactorySame list and moreBuild info, promotion features
GitHub Packages, GitLab Registry, cloud registries (ECR, ACR, GAR)Packages and imagesGood when you are in that platform
S3 or other object storageAny fileCheap and simple for raw artifacts

Publish to Nexus With Maven

xml <!-- pom.xml --> <distributionManagement> <repository> <id>nexus-releases</id> <url>https://nexus.example.com/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <url>https://nexus.example.com/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
groovy stage('Publish') { when { branch 'main' } steps { configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) { // settings.xml with server credentials (Config File Provider plugin) sh 'mvn -B -s $MAVEN_SETTINGS -DskipTests deploy' } } }

Publish Other Types

groovy // npm package withCredentials([string(credentialsId: 'npm-token', variable: 'NPM_TOKEN')]) { sh 'echo "//registry.example.com/:_authToken=${NPM_TOKEN}" > .npmrc && npm publish && rm .npmrc' } // Python package withCredentials([usernamePassword(credentialsId: 'pypi-internal', usernameVariable: 'U', passwordVariable: 'P')]) { sh 'python -m build && twine upload --repository-url https://nexus.example.com/repository/pypi-hosted/ -u $U -p $P dist/*' } // Raw file with curl withCredentials([usernamePassword(credentialsId: 'nexus', usernameVariable: 'U', passwordVariable: 'P')]) { sh 'curl -fsS -u "$U:$P" --upload-file app.tgz https://nexus.example.com/repository/raw-hosted/shop/${VERSION}/app.tgz' } // Helm chart sh 'helm package chart/ --version ${VERSION} --app-version ${VERSION}' sh 'helm push shop-${VERSION}.tgz oci://registry.example.com/charts'

Version Numbers

SchemeExampleNotes
Semantic VersioningMAJOR.MINOR.PATCH such as 2.3.1MAJOR: breaking change, MINOR: new feature, PATCH: bug fix
Build number1.4.${BUILD_NUMBER}Easy, but numbers depend on the Jenkins job
Git SHA3f9c2abExact commit. Great as metadata or an image tag
Both1.4.27+3f9c2abSemVer plus build metadata: best for traceability
Calendar versioning2026.11.17.3Fits frequently released services
groovy pipeline { agent any environment { SHORT_SHA = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() BASE_VER = readFile('VERSION').trim() // file holds 1.4 VERSION = "${BASE_VER}.${env.BUILD_NUMBER}+${SHORT_SHA}" } stages { stage('Build') { steps { echo "Version ${VERSION}" sh 'mvn -B -Drevision=${BASE_VER}.${BUILD_NUMBER} package' } } } }

Tag-Driven Releases

A common, simple flow: a Git tag starts the release. The tag is the version, set by a person, or by an automatic tool from commit messages (semantic-release, release-please, GitVersion).

groovy stage('Release') { when { buildingTag() } // multibranch with tag discovery steps { script { if (!(env.TAG_NAME ==~ /^v\d+\.\d+\.\d+$/)) { error "Bad tag ${env.TAG_NAME}" } env.RELEASE_VERSION = env.TAG_NAME.substring(1) } sh 'mvn -B versions:set -DnewVersion=$RELEASE_VERSION -DgenerateBackupPoms=false' sh 'mvn -B -DskipTests deploy' sh 'docker build -t registry.example.com/team/shop:$RELEASE_VERSION .' sh 'docker push registry.example.com/team/shop:$RELEASE_VERSION' } }

Promotion Without Rebuilding

  • Promote by copying or retagging the same artifact, never by rebuilding
  • For images, promote by digest: docker buildx imagetools create -t registry/prod/app:1.4.2 registry/dev/app@sha256:...
  • In Artifactory or Nexus use repositories like dev, staging, release, and move builds between them after tests pass
  • Record in the artifact metadata the Git commit, build URL and test results, so every deployed file can be traced

Retention and Cleanup

WhatPolicy idea
Snapshots and dev buildsDelete after 14 to 30 days
Release artifactsKeep for the support life of the product
Docker images in devKeep the last N tags per branch
Jenkins build artifactsKeep few; the repository manager is the long-term store

Practice Tasks

  1. Archive an artifact with fingerprints and find where it was used
  2. Publish a package to a Nexus or Artifactory lab server from the pipeline
  3. Create a version string with SemVer plus build metadata and show it in the artifact name
  4. Build a release job that runs only for tags matching vX.Y.Z
  5. Write the steps to promote an image from dev to prod by digest

Conclusion

Store artifacts in a repository manager, not only in Jenkins, version them with Semantic Versioning plus build metadata, drive releases from Git tags, and promote the same artifact through environments instead of rebuilding. Keep retention rules so storage stays under control.

Quick Summary: build once promote same; archive + fingerprint; repo managers; publish Maven/npm/PyPI/raw/Helm; version schemes; tag releases; promotion by digest; retention.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators