Push and Clean Up

Pushing the Image and Cleaning Up Local Layers

image.push() tags and pushes the build's tag, and image.push('main') the moving one. Only changed layers travel; the rest were in the registry since build 4 (Already exists or Layer already exists):

The pushes in main's build 5Shell
curl -s -u "admin:$JENKINS_TOKEN" http://localhost:32080/job/booknest/job/main/5/consoleText \
  | grep -E '^\+ docker push|digest:|Already exists' | cut -c1-95
Output
+ docker push localhost:32550/booknest-api:main-e2d7a8a-5
44136fa355b3: Already exists
main-e2d7a8a-5: digest: sha256:ce8fc961d13c9174daa175e4c76e45f92b459bd20ce0dc01a1e4ddec51e438c3
+ docker push localhost:32550/booknest-api:main
13fccd044706: Already exists
44136fa355b3: Already exists
main: digest: sha256:ce8fc961d13c9174daa175e4c76e45f92b459bd20ce0dc01a1e4ddec51e438c3 size: 856

Both tags point to the same digest. An agent that builds images all day fills its disk, so the pipeline cleans up after itself: the Test stage's down -v --rmi local removes the test image, database volume and network, and a post { always { ... } } block removes the two local tags:

Cleaning up local tags after every build (excerpt)Groovy
  post {
    always {
      sh 'docker image rm -f "$IMAGE:$TAG" "$IMAGE:main" || true'
    }

|| true keeps a build that failed before tagging from failing again here. The build cache survives, so the next build stays fast; a scheduled docker builder prune --filter until=72h trims it, and the registry needs its own retention (Image Cleanup).