Since 02-04, the orders-api jar has been stored with archiveArtifacts in the history of each build. That is useful for downloading it and for fingerprints, but it is not a place where other systems can look up "version 1.0.0 of orders-api": builds are deleted by the retention policy, the storage is the controller's disk and nothing stops two builds from producing "the same" version with different content. On top of that, every build downloads its dependencies straight from the Internet. An artifact repository solves both problems: it stores what TecnoShop produces in an orderly, versioned and immutable way, and it acts as a controlled intermediary for what TecnoShop consumes. In this lesson you will set up Nexus Repository in the lab, make Maven and npm download their dependencies through it, add a Publish stage with ./mvnw deploy to orders-api, define TecnoShop's SNAPSHOT and release versioning policy, review traceability and get to know container image registries, which you will use in module 8.
Why an Artifact Repository
| Need | archiveArtifacts in Jenkins |
Artifact repository |
|---|---|---|
| Finding a specific version | You have to know which build generated it | By coordinates: com.tecnoshop:orders-api:1.0.0 |
| Lifetime | Until the retention policy deletes the build | Whatever the organization decides (releases, usually forever) |
| Immutability | No: another build can generate another "1.0.0" jar | Yes: a published release cannot be overwritten |
| Consumption from other tools | Download through a Jenkins URL | Maven, Gradle, npm, Docker, Ansible... understand it natively |
| Third-party dependencies | Downloaded from the Internet on every agent | Downloaded once and served from the repository cache (proxy) |
| Availability if Maven Central or npmjs goes down | Builds fail | They keep working with what is already in the cache |
| Control over what comes in | None | A single point everything goes through, auditable and filterable |
| Promotion between environments | Copying files between builds | The same immutable artifact is deployed to dev, staging and production |
| Storage | The controller's disk | A dedicated server, object storage... |
archiveArtifacts does not go away: it is still useful for seeing in each build what it produced (build-info.txt, dependencies.txt) and for fingerprints. But the source of truth for artifacts becomes the repository.
Concepts: Hosted, Proxy and Group Repositories
Repository managers (Nexus, Artifactory and others) organize content into repositories of a given format (Maven, npm, Docker, PyPI...) and of one of these three types:
| Type | What it contains | Example at TecnoShop |
|---|---|---|
| Hosted | The organization's own artifacts, published by it | maven-releases, maven-snapshots, npm-private |
| Proxy | A cache of a remote repository: it downloads on demand and keeps a copy | maven-central (of Maven Central), npm-registry (of registry.npmjs.org) |
| Group | A single URL that groups several repositories and searches them in order | maven-public = releases + snapshots + maven-central; npm-public = npm-private + npm-registry |
flowchart LR
B["Build on linux-agent-01"] -->|"downloads dependencies"| G["maven-public (group)"]
G --> R["maven-releases (hosted)"]
G --> S["maven-snapshots (hosted)"]
G --> P["maven-central (proxy)"]
P -->|"only the first time"| C["Maven Central (Internet)"]
B -->|"./mvnw deploy"| R
B -->|"./mvnw deploy (SNAPSHOT)"| S
Builds always read from the group (a single URL) and publish to the appropriate hosted repository.
Nexus Repository Community in the Lab
At TecnoShop, the repository is nexus.tecnoshop.local. In the lab you will use Nexus Repository Community Edition, Sonatype's free edition. Keep in mind that this edition has usage limits (on the number of components and requests) intended for small teams, and that its features and its default database have changed in recent versions: check the documentation for the version you install.
Resources. Nexus is a Java application that recommends several GB of RAM. In the lab you will limit it to a 1 GB heap. With SonarQube, Jenkins and the agent running at the same time, a 16 GB laptop has room to spare; with 8 GB, stop the services you are not using (
docker compose stop sonarqube sonarqube-db). Watch out: from this lesson on, Maven builds need Nexus.
Add the service to docker-compose.yml:
nexus:
image: sonatype/nexus3:<version> # pin a specific version, as in 05-04
container_name: nexus
restart: unless-stopped
environment:
INSTALL4J_ADD_VM_PARAMS: "-Xms1g -Xmx1g -XX:MaxDirectMemorySize=1g"
ports:
- "127.0.0.1:8082:8081"
volumes:
- nexus_data:/nexus-data
volumes:
# ... the existing volumes ...
nexus_data:
name: nexus_dataINSTALL4J_ADD_VM_PARAMS: options for the Nexus JVM.-Xms1g -Xmx1gsets the heap to 1 GB;MaxDirectMemorySizelimits off-heap memory."127.0.0.1:8082:8081": inside the Compose network, Nexus listens on8081(http://nexus:8081), but on the host it is published on8082, because8081is used byorders-apiwhen you start it on your machine (it has been itsserver.portsince 01-04). And, like the other auxiliary services, only on127.0.0.1.nexus_data: all of Nexus' state (configuration, database and, by default, artifact storage). Include it in your backups, just likejenkins_homein 05-03.
| Name | At TecnoShop | In the lab, from Jenkins and the agent | In the lab, from your browser |
|---|---|---|---|
| Nexus | https://nexus.tecnoshop.local |
http://nexus:8081 |
http://localhost:8082 |
The first startup takes several minutes. Wait until you see Started Sonatype Nexus.
First Login and the TecnoShop Repositories
First Login
The initial admin password is in a file inside the volume:
Log in at http://localhost:8082 with admin and that password. The setup wizard will ask you for:
- A new password for
admin(theadmin.passwordfile disappears afterward). - Whether to allow anonymous access. TecnoShop allows it for reading only, within its internal network: that way builds and developers download dependencies without credentials, and the credential with publishing permission is only used where publishing happens. The default anonymous role grants reading and browsing; do not extend it.
The Repositories
When it is installed, Nexus creates the most common Maven repositories; check in Server administration (gear icon) → Repository → Repositories that they exist and review their configuration:
| Repository | Type | Key configuration |
|---|---|---|
maven-releases |
Maven hosted | Version policy: Release; Deployment policy: Disable redeploy |
maven-snapshots |
Maven hosted | Version policy: Snapshot; Deployment policy: Allow redeploy |
maven-central |
Maven proxy | Remote storage: https://repo1.maven.org/maven2/ |
maven-public |
Maven group | Members: maven-releases, maven-snapshots, maven-central |
- Disable redeploy on
maven-releasesis immutability: onceorders-api-1.0.0.jaris published, no build can replace it. If one tries, Nexus responds with an error and the build fails. maven-snapshotsallows redeployment because SNAPSHOT versions are, by definition, versions under development.
Use Create repository to create the npm ones:
| Repository | Recipe | Configuration |
|---|---|---|
npm-registry |
npm (proxy) | Remote storage: https://registry.npmjs.org |
npm-private |
npm (hosted) | Deployment policy: Disable redeploy |
npm-public |
npm (group) | Members, in this order: npm-private, npm-registry |
And a container image repository, to be used in 08-01:
| Repository | Recipe | Configuration |
|---|---|---|
docker-tecnoshop |
docker (hosted) | An HTTP connector on port 8083 (not published on the host for now); Deployment policy: Disable redeploy |
In Security → Realms, enable npm Bearer Token Realm and Docker Bearer Token Realm: they are the mechanisms npm and Docker use to authenticate against Nexus.
The jenkins-deployer User and the nexus-deployer Credential
A Role with Just Enough
Security → Roles → Create role → Nexus role: ID tecnoshop-publishing, with these privileges:
| Privilege | What for |
|---|---|
nx-repository-view-maven2-maven-releases-* except delete (that is, add, edit, read, browse) |
Publishing releases |
nx-repository-view-maven2-maven-snapshots-* except delete |
Publishing SNAPSHOTs |
nx-repository-view-npm-npm-private-* except delete |
Publishing in-house npm packages (should the need arise) |
nx-repository-view-docker-docker-tecnoshop-* except delete |
Pushing images in module 8 |
- No
deleteon any repository: the Jenkins account can publish, but not delete. A compromised script could not remove releases. editis needed because Maven updates metadata files (maven-metadata.xml) when it publishes. The Disable redeploy policy still prevents a release from being overwritten.- Privilege names follow the pattern
nx-repository-view-<format>-<repository>-<action>; the form's search box filters them.
The User
Security → Users → Create local user: ID jenkins-deployer, a fictitious email address ([email protected]), a long random password, status Active, role tecnoshop-publishing.
The Credential
In 04-04 you created nexus-deployer with fake values (ci-deployer and NotARealPassword-123). Now it has a real use: in Manage Jenkins → Credentials, open nexus-deployer, click Update and change Username to jenkins-deployer and Password to the Nexus user's password. Update the description: Nexus: jenkins-deployer user (publishes to maven-releases/snapshots, npm-private and docker-tecnoshop; no delete). Owner: Laura. The ID does not change, so nothing else notices.
Dependencies Through Nexus: Enabling the Mirror
Laura edits the maven-settings-tecnoshop managed file from 06-02 (which gained the SonarQube pluginGroup in 06-04) and enables the mirror:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<!-- Managed from Jenkins (Managed files). Do not copy it into the repositories. -->
<interactiveMode>false</interactiveMode>
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<mirrors>
<mirror>
<id>nexus-tecnoshop</id>
<name>TecnoShop Nexus (maven-public group)</name>
<mirrorOf>*</mirrorOf>
<url>http://nexus:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>tecnoshop</id>
<properties>
<nexus.url>http://nexus:8081</nexus.url>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>tecnoshop</activeProfile>
</activeProfiles>
</settings><mirrorOf>*</mirrorOf>: all requests for dependencies and plugins, to any repository (Maven Central or any declared in apom.xml), go tomaven-public. This is the measure against the cache poisoning from exercise 3 in 06-02: a<repositories>block added in a PR no longer has any effect, because Maven does not go out to any URL other than Nexus.http://nexus:8081/...: the lab URL, inside the Compose network. At TecnoShop it would behttps://nexus.tecnoshop.local/repository/maven-public/.- The
tecnoshopprofile, always active, defines thenexus.urlproperty thatpom.xmlwill use for publishing. Properties from an active settings profile take precedence over those inpom.xml, so in Jenkinsnexus.urlwill take the lab value.
Run an orders-api build. In the console, downloads no longer mention repo.maven.apache.org, but nexus:8081. In Nexus, Browse → maven-central shows the components that have been stored in the cache.
HTTP in the lab. Since Maven 3.8.1, Maven blocks external repositories over unencrypted HTTP by default; if you see an error mentioning
maven-default-http-blockerorBlocked mirror for repositories, check that there are nohttp://repositories declared inpom.xml. At TecnoShop, Nexus is always served over HTTPS; the lab's HTTP is a concession, just like Jenkins'http://localhost:8080/.
Publishing with Maven: distributionManagement and the Publishing Settings
The pom.xml
For ./mvnw deploy to know where to publish, the orders-api pom.xml needs a distributionManagement block (at the same level as <build>) and a property with the default URL:
<properties>
<!-- ... earlier properties ... -->
<nexus.url>https://nexus.tecnoshop.local</nexus.url>
<project.build.outputTimestamp>2026-01-01T00:00:00Z</project.build.outputTimestamp>
</properties>
<distributionManagement>
<repository>
<id>nexus-tecnoshop</id>
<name>TecnoShop releases</name>
<url>${nexus.url}/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-tecnoshop</id>
<name>TecnoShop snapshots</name>
<url>${nexus.url}/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement><repository>: where final versions (without-SNAPSHOT) are published.<snapshotRepository>: where SNAPSHOT versions are published. Maven picks one or the other automatically based on the project version.<id>nexus-tecnoshop</id>: the identifier Maven will use to look up the credentials in the<servers>section of the settings. Both entries can share it because they use the same account.${nexus.url}: it ishttps://nexus.tecnoshop.localby default (TecnoShop's real URL) andhttp://nexus:8081in the lab, thanks to the profile in the managed settings.project.build.outputTimestamp: fixes the timestamp of the entries in the packaged files, so the same code produces a byte-for-byte identical jar (a reproducible build). You will need it in the traceability section.- No username or password: never in
pom.xml.
Settings Just for Publishing: maven-settings-tecnoshop-publish
The publishing credentials should not be within reach of every build: a PR has no reason to receive them. That is why Laura does not add them to maven-settings-tecnoshop (the one every build uses through MAVEN_SETTINGS_ID), but to a second managed file that is only used in the publishing stage.
Manage Jenkins → Managed files → Add a new Config → Maven settings.xml, ID maven-settings-tecnoshop-publish:
- Content: the same XML as
maven-settings-tecnoshop. - Server Credentials → Add: ServerId
nexus-tecnoshop, Credentialsnexus-deployer. - Replace All: checked.
When it hands over this file, Config File Provider adds to its content (or replaces, because of Replace All) an entry like this one, with the credential's username and password:
<servers>
<server>
<id>nexus-tecnoshop</id>
<username>jenkins-deployer</username>
<password>****</password>
</server>
</servers>- The password only exists in the temporary file for as long as the
configFileProviderblock lasts, and Jenkins masks it if it shows up in the log. - The drawback is that the common content is duplicated in two files: when Laura changes the mirror, she has to change it in both. Managing the Jenkins configuration as code (08-03) helps avoid that drift.
- Against a malicious
Jenkinsfilewritten by someone with write permission, this separation is not enough (they could request the file themselves): the real protection is the Trust policy and the review from 04-05. What it does achieve is keeping regular builds from handling credentials they do not need.
The Publish Stage
stage('Publish') {
when {
allOf {
expression { params.RUN_TESTS }
anyOf {
allOf {
branch 'main'
expression { env.APP_VERSION.endsWith('-SNAPSHOT') }
}
tag pattern: 'v\\d+\\.\\d+\\.\\d+', comparator: 'REGEXP'
}
}
}
options {
timeout(time: 5, unit: 'MINUTES')
}
steps {
sh label: 'Check that the tag matches the version', script: '''
if [ -n "${TAG_NAME:-}" ] && [ "$TAG_NAME" != "v$APP_VERSION" ]; then
echo "ERROR: the tag $TAG_NAME does not match the pom version ($APP_VERSION)"
exit 1
fi
'''
mavenTecnoShop goals: '-DskipTests -Dmaven.install.skip=true deploy',
settings: 'maven-settings-tecnoshop-publish',
label: 'Publish to Nexus'
}
}The when condition, from the inside out:
branch 'main'and the version ends in-SNAPSHOT: everymainbuild publishes its SNAPSHOT.- Or
tag pattern: 'v\\d+\\.\\d+\\.\\d+', comparator: 'REGEXP': the build of a version-shaped tag (v1.0.0) publishes the release. This is the tag discovery you enabled in 06-01. In the Groovy string,\\dproduces the regular expression's\d("a digit"). - And, in any case,
RUN_TESTS: nothing is ever published without being tested. - PRs and other branches publish nothing.
The steps:
- Tag check: in a tag build,
TAG_NAMEmust be exactlyvplus thepom.xmlversion. If someone tagsv1.0.0on a commit whosepom.xmlsays1.1.0-SNAPSHOT, the build fails with a clear message instead of publishing something inconsistent.${TAG_NAME:-}is empty if the variable does not exist (branch builds), and everything is resolved in the shell, without interpolating external data with Groovy. mavenTecnoShop ... settings: 'maven-settings-tecnoshop-publish': thesettingsparameter from versionv1.2.0of the library overrides the generalMAVEN_SETTINGS_ID, for this call only.-DskipTests: the tests have already run in their stages.-Dmaven.install.skip=true: thedeployphase includesinstall, which would copy the jar into the agent's shared local cache; that is the contamination we wanted to avoid in 06-02.deploy: goes through the lifecycle up todeploy, which uploads the jar, thepom.xmland their checksums to Nexus.
The stage goes after Smoke and before Deploy to dev: only what has passed the tests, the analysis and the smoke check gets published, and whatever is deployed afterward will be what was published.
In the console of a main build you will see something similar to:
[INFO] --- deploy:3.1.x:deploy (default-deploy) @ orders-api --- Uploading to nexus-tecnoshop: http://nexus:8081/repository/maven-snapshots/com/tecnoshop/orders-api/1.0.0-SNAPSHOT/orders-api-1.0.0-20261128.101530-1.jar Uploaded to nexus-tecnoshop: http://nexus:8081/repository/maven-snapshots/com/tecnoshop/orders-api/1.0.0-SNAPSHOT/orders-api-1.0.0-20261128.101530-1.jar (21 MB at 48 MB/s) Uploading to nexus-tecnoshop: .../orders-api-1.0.0-20261128.101530-1.pom Uploading to nexus-tecnoshop: .../maven-metadata.xml
Look at the name: when publishing a SNAPSHOT, Maven replaces SNAPSHOT with a timestamp and a sequence number (20261128.101530-1). Every main build adds a new one; maven-metadata.xml says which is the latest. Anyone requesting 1.0.0-SNAPSHOT gets the most recent one.
SNAPSHOT and Release: TecnoShop's Versioning Policy
SNAPSHOT (1.1.0-SNAPSHOT) |
Release (1.1.0) |
|
|---|---|---|
| Meaning | "The upcoming 1.1.0, under development" | A finished version |
| Content | Changes with every publication | Never changes |
| Repository | maven-snapshots (redeployment allowed) |
maven-releases (Disable redeploy) |
| Who publishes it | Every main build |
The build of the v1.1.0 tag |
| What it is for | Continuous integration between teams, testing in dev |
Deployments to staging and production, stable dependencies |
TecnoShop uses semantic versioning MAJOR.MINOR.PATCH, with the same logic as the library in 04-06: PATCH for compatible fixes, MINOR for compatible features and MAJOR for incompatible changes (for example, a change to the response format of /api/orders that breaks its clients).
The policy's rules:
mainis always on a SNAPSHOT version: the next one to be published.- A release is created with a
vX.Y.Ztag on a commit whosepom.xmlhas versionX.Y.Z, and it is published from the build of that tag. - A published release is never modified. If it has a bug,
X.Y.(Z+1)is published. - No project deployed to
stagingorproductiondepends on SNAPSHOT versions.
Publishing a Release: From 1.0.0-SNAPSHOT to 1.0.0
orders-api has been at 1.0.0-SNAPSHOT since module 1. Diego is going to publish 1.0.0. Because main is protected (06-01), the version change arrives through a PR:
git switch main && git pull
git switch -c release/1.0.0
./mvnw -B versions:set -DnewVersion=1.0.0 -DgenerateBackupPoms=false
git commit -am "Version 1.0.0"
git tag -a v1.0.0 -m "orders-api 1.0.0"
./mvnw -B versions:set -DnewVersion=1.1.0-SNAPSHOT -DgenerateBackupPoms=false
git commit -am "Start development of 1.1.0-SNAPSHOT"
git push -u origin release/1.0.0versions:set -DnewVersion=1.0.0: Maven's Versions plugin changes the version inpom.xml(and in the modules, if there were any).-DgenerateBackupPoms=falsekeeps it from leavingpom.xml.versionsBackupfiles behind.- The first commit has version
1.0.0, and thev1.0.0tag points to it. - The second commit moves on to the next development version. Choosing
1.1.0rather than1.0.1is a forecast: what comes next will be new features. - The branch is pushed; the tag, not yet.
Then:
- Diego opens the PR for
release/1.0.0; the multibranch builds it and, once approved, it is merged with Create a merge commit. That way both commits (and the tagged one) stay in the history ofmain. With squash, the1.0.0commit would disappear and the tag would be left outsidemain. - He pushes the tag:
git push origin v1.0.0. - In Jenkins,
orders-api→ Tags tab →v1.0.0→ Build Now (tags are not built on their own, as you saw in 06-01). - The tag build compiles, tests, packages, passes
Smokeand, inPublish, uploadsorders-api-1.0.0.jartomaven-releases. It does not runQuality analysisorDeploy to dev, which requirebranch 'main'.
Meanwhile, the main build after the merge publishes 1.1.0-SNAPSHOT. And if someone reruns the v1.0.0 build, Publish will fail: Nexus refuses to overwrite a release. That is immutability at work.
It is a good idea to protect the v* tags in GitHub (Settings → Rules → Rulesets → New tag ruleset), just as you did with the library's tags, so nobody can move or delete them.
Alternatives for Automating the Process
- Maven Release Plugin (
release:prepareandrelease:perform): does all these steps (changing versions, commits, tag, publishing) with a single command. It requires whoever runs it to be able to write to the repository, which in CI means giving Jenkins push permission (which the App from 06-01 deliberately lacks) and dealing with the protection onmain. It is a valid option for many teams; for now, TecnoShop prefers the explicit process. - "CI-friendly" versions: Maven supports
<version>${revision}</version>inpom.xml, with the value passed as-Drevision=...from the pipeline (and the Flatten plugin to publish a resolvedpom.xml). It lets you derive the version from the tag without version commits. It is powerful, but it changes the way developers work with the version.
Fully automated delivery, with promotion between environments, is designed in Setting Up a CD Pipeline.
npm Through Nexus in catalog-web
The same principle applies to npm: Laura edits the npmrc-tecnoshop managed file:
# .npmrc for the TecnoShop builds (managed from Jenkins)
registry=http://nexus:8081/repository/npm-public/
fund=false
update-notifier=falseregistry: thenpm-publicgroup, which serves in-house packages fromnpm-privatefirst and then public ones through thenpm-registrycache.- With anonymous read access, no authentication is needed to install. If a project published packages to
npm-private, a second managed file would be used, with the NPM Registry section associated withnexus-deployer, just as with Maven. - The
catalog-webpackage-lock.jsoncontainsregistry.npmjs.orgURLs. Current versions of npm replace that host with the configured registry when installing (thereplace-registry-hostoption, whose default value acts on the public registry), so there is no need to regenerate the lockfile. If you see downloads still going toregistry.npmjs.org, check the npm version of each Node installation.
On the next catalog-web build, Browse → npm-registry in Nexus shows Jest and its dependencies in the cache.
Traceability: Fingerprints, build-info and Metadata
Traceability means being able to answer, for any deployed artifact, where it comes from: which commit, which build, which tests it passed. The pieces TecnoShop already has:
| Piece | Where | What it answers |
|---|---|---|
build-info.txt (infoBuild step) |
Build artifacts in Jenkins | Application, version, branch, commit, build, image and build URL |
Fingerprints from archiveArtifacts |
Jenkins | Which builds produced or used a file with that MD5 checksum |
| Component metadata in Nexus | Nexus (Browse → component) | Publication date, user who published it (jenkins-deployer), SHA-1, SHA-256 and MD5 checksums |
Git tag vX.Y.Z |
GitHub | The exact commit of each release |
| Build description | Jenkins | orders-api 1.0.0 (v1.0.0) |
There is an important detail: the Publish stage runs deploy, which packages the jar again. Is it the same file that was archived, tested in Smoke and fingerprinted in Jenkins? Thanks to project.build.outputTimestamp, Maven and the Spring Boot plugin generate reproducible archives: same code, same result byte for byte. You can check it by comparing the MD5 checksum of the jar archived in the build with the one Nexus shows for the same component: they should match. Without that property, each packaging would have different timestamps inside the jar and the checksums would never match.
Some repositories also let you attach properties to each artifact (build number, commit, test results) and store a complete build record (build-info): Artifactory does this with its CLI and its integrations. Nexus Community does not offer arbitrary per-artifact properties, so at TecnoShop that information lives in build-info.txt and in the jar itself. Spring Boot can include a META-INF/build-info.properties file in the jar with the build-info goal of spring-boot-maven-plugin, which the /actuator/info endpoint can expose; that way a deployed service "says" which version it is.
Container Image Registries
In module 8, orders-api will also be packaged as a container image. The concepts:
| Concept | What it is | Example at TecnoShop |
|---|---|---|
| Registry | The server that stores images | registry.tecnoshop.local |
| Repository | An application's images within the registry | registry.tecnoshop.local/orders-api (the IMAGE variable since 04-03) |
| Tag | A readable name for an image; it can be moved to another image | 1.1.0-SNAPSHOT-57 (the IMAGE_TAG variable) |
| Digest | The SHA-256 checksum of the content; it identifies the image immutably | sha256:4f1c...fake |
| Full reference | Repository + tag, or repository + digest | registry.tecnoshop.local/orders-api@sha256:4f1c... |
At TecnoShop, registry.tecnoshop.local is the name of the company registry (which may be the Nexus docker-tecnoshop repository published behind an HTTPS proxy, or a dedicated product such as Harbor). The tagging policy:
- Every build that builds an image tags it with
${APP_VERSION}-${BUILD_NUMBER}(IMAGE_TAG): unique per build and easy to trace back to it. - Releases also get the version tag (
1.0.0). latestis never deployed: it does not say which version it is and it changes without warning.- Deployments record and use the digest: even if someone moved a tag, the digest still points to the tested image. The registry should prevent tags from being moved (in Nexus, Disable redeploy; in other products, tag immutability rules).
Create the credential the pipeline will use now, with fake values until module 8: Username with password, ID registry-tecnoshop, username jenkins-push, password NotARealPassword-456, description Image registry registry.tecnoshop.local (push). Real value in 08-01.
As a preview, this is what the stage will look like (do not add it: linux-agent-01 does not have Docker, and building images is covered in Jenkins with Docker):
// PREVIEW of 08-01: requires an agent with Docker
stage('Image') {
steps {
withCredentials([usernamePassword(credentialsId: 'registry-tecnoshop',
usernameVariable: 'REGISTRY_USER',
passwordVariable: 'REGISTRY_PASSWORD')]) {
sh '''
echo "$REGISTRY_PASSWORD" | docker login registry.tecnoshop.local -u "$REGISTRY_USER" --password-stdin
docker build -t "$IMAGE:$IMAGE_TAG" .
docker push "$IMAGE:$IMAGE_TAG"
docker inspect --format '{{index .RepoDigests 0}}' "$IMAGE:$IMAGE_TAG" > image-digest.txt
'''
}
archiveArtifacts artifacts: 'image-digest.txt'
}
}--password-stdin: the password comes in through standard input, not as a process argument, as recommended in 04-04.docker inspect --format '{{index .RepoDigests 0}}': gets the digest reference of the image just pushed, which is archived so the deployment can use it.
Other Solutions: A Comparison
| Product | Formats | Model | Things to keep in mind |
|---|---|---|---|
| Nexus Repository (Sonatype) | Maven, npm, Docker, PyPI, NuGet, Helm, raw... | Self-managed: Community (free, with usage limits) and Pro | Very widespread in Java environments |
| Artifactory (JFrog) | Practically all of them | Self-managed or cloud; paid versions (and a limited free edition) | Very complete build-info, properties and promotion |
| GitHub Packages | Maven, npm, NuGet, RubyGems, containers (ghcr.io) |
GitHub service | Integrated with GitHub repositories and permissions; does not act as a general proxy for public repositories |
| Harbor | Container images and OCI artifacts (Helm) | Self-managed, open source (CNCF) | Vulnerability scanning, signatures, replication, tag immutability rules |
| Amazon ECR | Container / OCI images | AWS service | Integrated with IAM and AWS container services |
| Azure Container Registry | Container / OCI images | Azure service | Integrated with Entra ID and AKS |
| Google Artifact Registry | Containers, Maven, npm, Python... | Google Cloud service | Replaces the old Container Registry (GCR), now retired |
The choice usually depends on where deployments run (in a specific cloud, its integrated registry simplifies permissions) and on how many formats you need. Jenkins integrates with all of them in the same way: credentials, the build tool or docker, and the corresponding URL.
Retention and Cleanup
An artifact repository grows nonstop: every main build adds a 20 MB SNAPSHOT, and the proxy caches keep everything that was ever downloaded. You need to decide what is kept.
| Content | TecnoShop policy |
|---|---|
Releases (maven-releases, npm-private) |
Kept forever (they may be needed to roll back or for audits) |
SNAPSHOTs (maven-snapshots) |
Those older than 30 days, keeping at least the last 5 of each version |
| Development build images | Those older than 30 days that are not deployed |
Proxy cache (maven-central, npm-registry) |
Anything not downloaded in 180 days |
In Nexus:
- Repository → Cleanup Policies → Create Cleanup Policy: a name (for example,
snapshots-30-days), the format and the criteria (component age, last download, version type). The available criteria depend on the edition and version. - Associate the policy with each repository in its configuration (Cleanup policies).
- System → Tasks: the Admin - Cleanup repositories using their associated policies task applies the policies (one is created by default, scheduled daily); for Maven SNAPSHOTs there is also a specific task that keeps a minimum per version.
- Deleting components does not free disk space right away: the Admin - Compact blob store task reclaims the storage space.
Always test a new policy with a preview (if your version offers one) or on a test repository before applying it: a badly chosen criterion deletes what it should not, and an artifact repository has no recycle bin.
Common Mistakes and Tips
401 Unauthorizedwhen publishing: thedistributionManagement<id>does not match the ServerId in Server Credentials, or the stage uses the general settings instead of the publishing ones.400 Bad Request/Repository does not allow updating assetswhen publishing a release: you are trying to overwrite a version that has already been published. That is expected; publish a new version.- Publishing a version without
-SNAPSHOTfrommainbecause of a mistake inpom.xml: thePublishcondition prevents it; if it did not, a version that was never tagged would be taken forever. - Exposing Nexus on port 8081 of the host: it clashes with
orders-apiwhen you start it locally. - Builds that suddenly fail to download dependencies: Nexus is stopped or starting up. From this lesson on it is a dependency of every Maven and npm build; monitor it just like Jenkins (05-05).
- Reading
APP_VERSIONwithout settings: the./mvnw help:evaluatein theenvironmentblock does not use the mirror. It works because thehelpplugin is already in the agent's cache; on a network without Internet access, that step would also need the managed settings. - Using
latestas the deployment tag: there is no way to know what was deployed or to roll back safely. - Tip: the
jenkins-deployeruser should not be able to do anything in the Nexus interface other than publish. Review its privileges every time you add a repository, so you do not extend them "just in case".
Exercises
Exercise 1. Set up Nexus, enable the mirror and add the Publish stage. After two main builds, look for the published SNAPSHOTs in Nexus. How many are there and how can you tell them apart? Download maven-metadata.xml from the 1.0.0-SNAPSHOT directory and find the latest one. Then compare the MD5 checksum of the jar archived in the last build with the one in Nexus.
Exercise 2. Follow the release process to publish orders-api 1.0.0. Then rerun the build of the v1.0.0 tag. What happens, and in which stage? And what if someone mistakenly creates the v1.2.0 tag on the latest main commit?
Exercise 3. The shipments-api team (the one from the review in 04-07) used to publish with curl -u ... --upload-file target/shipments-api.jar https://nexus.tecnoshop.local/repository/shipments/. Rewrite their Publish to Nexus stage with what you have learned and list what the team gains.
Solutions
Solution 1. There are two versions of the jar in maven-snapshots/com/tecnoshop/orders-api/1.0.0-SNAPSHOT/ (or whatever version your main is on), with names such as orders-api-1.0.0-20261128.101530-1.jar and orders-api-1.0.0-20261128.113204-2.jar: they are distinguished by the publication timestamp and the trailing sequence number. In maven-metadata.xml, the <snapshot> block contains the <timestamp> and <buildNumber> of the latest one, and <snapshotVersions> lists each file with its resolved version. The MD5 checksum of the jar archived in Jenkins (build page → Artifacts, or its fingerprint) and that of the component in Nexus match thanks to project.build.outputTimestamp. If you removed that property, they would not match, because deploy repackages the jar with new timestamps.
Solution 2. When you rerun v1.0.0, every stage passes up to Publish, where deploy fails: Nexus responds with an error (usually 400) because maven-releases has Disable redeploy and orders-api-1.0.0.jar already exists. The build ends red without having changed anything in Nexus. With the v1.2.0 tag on the latest main commit (whose pom.xml says 1.1.0-SNAPSHOT), the tag matches the pattern, so Publish runs, but its first step compares TAG_NAME (v1.2.0) with v$APP_VERSION (v1.1.0-SNAPSHOT) and fails with the message the tag v1.2.0 does not match the pom version. Nothing is published. The wrong tag should be deleted (git push origin :refs/tags/v1.2.0, if the rules allow an administrator to do so) before anyone uses it.
Solution 3.
stage('Publish') {
when {
allOf {
expression { params.RUN_TESTS }
anyOf {
allOf {
branch 'main'
expression { env.APP_VERSION.endsWith('-SNAPSHOT') }
}
tag pattern: 'v\\d+\\.\\d+\\.\\d+', comparator: 'REGEXP'
}
}
}
options {
timeout(time: 5, unit: 'MINUTES')
}
steps {
mavenTecnoShop goals: '-DskipTests -Dmaven.install.skip=true deploy',
settings: 'maven-settings-tecnoshop-publish',
label: 'Publish to Nexus'
}
}With distributionManagement in their pom.xml (and APP_VERSION defined as in orders-api). What they gain: (1) the password is not passed as a curl argument, nor does the Jenkinsfile handle it: Config File Provider injects it into a temporary file; (2) the artifact is published with Maven coordinates (groupId, artifactId, version), with its pom.xml and checksums, instead of a loose file in a raw repository; (3) SNAPSHOTs and releases go to their own repositories, with the release immutable; (4) other projects can depend on shipments-api like any other library; (5) only main and version tags publish, never PRs; (6) SNAPSHOT cleanup and retention are handled by Nexus with its policies.
Conclusion
TecnoShop now has an artifact repository. You know why archiveArtifacts is not enough (immutability, versioning, dependency proxying, promotion) and how hosted, proxy and group repositories are organized. In the lab, Nexus Repository Community runs as the nexus service (http://nexus:8081 on the Compose network, http://localhost:8082 in your browser; nexus.tecnoshop.local at TecnoShop), with an immutable maven-releases, maven-snapshots, the maven-public group, the npm-registry, npm-private and npm-public npm repositories, the docker-tecnoshop image repository and the jenkins-deployer user without delete permissions, which the nexus-deployer credential now points to. Every build downloads its dependencies through the mirror in the managed settings and the managed .npmrc, and orders-api publishes with ./mvnw deploy in the Publish stage: SNAPSHOTs from main and releases from vX.Y.Z tags, with publishing settings that only that stage receives. You know TecnoShop's versioning policy, the process for publishing 1.0.0, the traceability pieces (including reproducible jars), image registry concepts with the ${APP_VERSION}-${BUILD_NUMBER} and digest tagging policy and the registry-tecnoshop credential, and how to clean up what is no longer needed. With a published, immutable artifact, what is left is to take it to a server and get it running. The Deploy to dev stage will stop being a simulation in Integrating with Deployment Tools.
