Artifacts¶
Manage build artifacts with Nexus Repository Manager.
Overview¶
Nexus provides artifact storage for Maven artifacts and Docker images. It supports versioning, access control, and repository management.
Access Nexus¶
Nexus is accessible at:
- Local: http://localhost:8081 (via port-forward)
Get admin password¶
Repository types¶
Maven repositories¶
- maven-releases: Production releases
- maven-snapshots: Development snapshots
Docker registry¶
- Registry:
nexus:5000(internal) orlocalhost:5000(via port-forward)
Publish Maven artifacts¶
Using Maven¶
mvn deploy:deploy-file \
-DgroupId=com.playpen \
-DartifactId=my-app \
-Dversion=1.0.0 \
-Dfile=target/my-app.jar \
-DrepositoryId=nexus \
-Durl=http://nexus:8081/repository/maven-releases
Using curl¶
curl -v \
-u username:password \
--upload-file my-app-1.0.0.jar \
http://nexus:8081/repository/maven-releases/com/playpen/my-app/1.0.0/my-app-1.0.0.jar
Push Docker images¶
Configure Docker registry¶
# Login to Nexus registry
docker login nexus:5000 -u username -p password
# Or via port-forward
docker login localhost:5000 -u username -p password
Push image¶
# Tag image
docker tag my-app:latest nexus:5000/my-app:1.0.0
# Push image
docker push nexus:5000/my-app:1.0.0
Pull image¶
Use in Kubernetes¶
Image pull secrets¶
Create secret for private registry:
kubectl create secret docker-registry nexus-registry-secret \
--docker-server=nexus:5000 \
--docker-username=username \
--docker-password=password \
-n playpen-apps
Use in deployment¶
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
template:
spec:
imagePullSecrets:
- name: nexus-registry-secret
containers:
- name: app
image: nexus:5000/my-app:1.0.0
Create repositories¶
Via Nexus UI¶
- Log in to Nexus
- Go to Settings → Repositories
- Create repository → Maven (hosted)
- Configure repository settings
Via API¶
curl -X POST \
-u admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "maven-custom",
"recipe": "maven2-hosted",
"online": true
}' \
http://nexus:8081/service/rest/v1/repositories/maven/hosted
Service accounts and API tokens¶
Create service account¶
- Log in to Nexus
- Go to Settings → Users → Create user
- Set role:
nx-repository-view-*-*-* - Create user
Generate API token¶
- Go to user profile
- Generate API token
- Use token for authentication:
Best practices¶
Versioning¶
- Use semantic versioning for releases
- Use snapshot versions for development
- Tag Docker images with version numbers
Access control¶
- Create service accounts for CI/CD
- Use API tokens instead of passwords
- Limit repository access by role
Cleanup¶
- Configure retention policies
- Remove old snapshots regularly
- Archive releases to external storage
Troubleshooting¶
Cannot push to registry¶
- Verify Docker login
- Check repository permissions
- Verify port-forward is active
Maven deploy fails¶
- Check repository URL
- Verify credentials
- Check network connectivity
Next steps¶
- Learn about CI/CD integration
- Configure platform services