Pipeline Stages
Dockerfile
Include thisDockerfile at the repo root to define your container:
- Starts from the lightweight
openjdk:8-jdk-alpineimage - Exposes port 8080 (Spring Boot default)
- Adds the JAR built by Maven
- Runs the JAR on container start
Initial Jenkinsfile
Add a Docker Build & Push stage after Maven build and unit tests:printenv lists all Jenkins environment variables. We leverage $GIT_COMMIT to tag images uniquely.Inspecting Images on the Jenkins VM
On the VM where Docker runs, list existing images:Push failure means Jenkins doesn’t have Docker Hub credentials configured.
Configuring Docker Hub Credentials in Jenkins
Ensure the Docker Pipeline plugin is installed:
- Go to Manage Jenkins → Manage Credentials → Global → Add Credentials
- Select Username with password
- Enter your Docker Hub username & password
- Set an ID (e.g.,
docker-hub) and save


Updated Jenkinsfile
Wrap Docker commands inwithDockerRegistry, referencing the credential ID:
An empty
url defaults to Docker Hub. Make sure credentialsId matches the ID you created.