A Minimal 3-Stage Jenkins Pipeline
October 19, 2025
Three stages are enough to take a repo from git to published images.
Stage mapping
| Stage | Name in Jenkinsfile | What it does |
|---|---|---|
| 1 | Pull Git Repository | git branch:'main', url:'<repo url>' |
| 2 | Build Docker Images | docker build backend2 + frontend2 images |
| 3 | Push to Docker Hub | docker login then docker push both images |
docker loginlives inside the Push stage, so it doesn't need a stage of its own.
Steps
- Jenkins → New Item → name → Pipeline → OK.
- Pipeline section → Pipeline script from SCM → Git → your repo URL →
branch
main→ Script PathJenkinsfile. Save. (Or paste the Jenkinsfile directly using Pipeline script.) - Add Docker Hub creds (ID
dockerhub-creds) under Manage Jenkins → Credentials. - Edit the placeholders:
YOUR_DOCKERHUB_USERNAME,YOUR_APP_NAME, and the repo URL. - Build Now → all 3 stages go green → verify the images on Docker Hub.
Final Jenkinsfile (3 stages)
pipeline {
agent any
environment {
DOCKERHUB_USER = 'YOUR_DOCKERHUB_USERNAME'
APP_NAME = 'YOUR_APP_NAME'
DOCKERHUB_CREDS = credentials('dockerhub-creds')
}
stages {
stage('Pull Git Repository') {
steps { git branch: 'main', url: 'https://github.com/YOUR_USERNAME/YOUR_REPO.git' }
}
stage('Build Docker Images') {
steps {
sh 'docker build -f backend2/DOCKERFILE -t $DOCKERHUB_USER/${APP_NAME}-backend:latest ./backend2'
sh 'docker build -f frontend2/DOCKERFILE -t $DOCKERHUB_USER/${APP_NAME}-frontend:latest ./frontend2'
}
}
stage('Push to Docker Hub') {
steps {
sh 'echo $DOCKERHUB_CREDS_PSW | docker login -u $DOCKERHUB_CREDS_USR --password-stdin'
sh 'docker push $DOCKERHUB_USER/${APP_NAME}-backend:latest'
sh 'docker push $DOCKERHUB_USER/${APP_NAME}-frontend:latest'
}
}
}
post { always { sh 'docker logout || true' } }
}
End-to-end flow
Install/run Jenkins → install plugins → add Docker Hub credentials → New Item →
Pipeline → Pipeline from SCM (your repo, Jenkinsfile) → Build Now → Jenkins
checks out the code → builds backend & frontend images → docker login → pushes
both images to Docker Hub → verify on Docker Hub.
Related: [[jenkins-jenkinsfile-explained]], [[docker-multi-container-app]].