Compare commits

...

5 Commits

Author SHA1 Message Date
VIPIN
7353b45f91 Fix deployment.yaml with correct Docker image name 2025-09-12 15:59:48 +05:30
VIPIN
de9f10b90b Fix 2025-09-12 15:32:29 +05:30
VIPIN
a3b38923d8 Fix BAT for Docker Hub push 2025-09-12 15:20:09 +05:30
VIPIN
c643bffb51 Fix credentials ID for Docker Hub push 2025-09-12 15:13:29 +05:30
VIPIN
a06fc69fce Updated Jenkinsfile for Docker + Kubernetes 2025-09-12 12:09:09 +05:30
2 changed files with 45 additions and 25 deletions

68
Jenkinsfile vendored
View File

@ -2,54 +2,74 @@ pipeline {
agent any agent any
environment { environment {
DOCKERHUB_USER = 'vipin2025devops' IMAGE_NAME = 'myapp'
IMAGE_NAME = 'myapp' IMAGE_TAG = 'latest'
IMAGE_TAG = "latest" DOCKERHUB_USER = 'vipin2025devops'
K8S_DEPLOYMENT = 'k8s/deployment.yaml' DEPLOYMENT_FILE = 'k8s/deployment.yaml'
K8S_SERVICE = 'k8s/service.yaml' SERVICE_FILE = 'k8s/service.yaml'
KUBECONFIG = 'C:\\Users\\rlkri\\.kube\\config'
} }
stages { stages {
stage('Checkout Code') { stage('Checkout Code') {
steps { steps {
checkout scm git branch: 'main',
url: 'https://git.opsmonsters.in/vipin.p/my-react-app.git',
credentialsId: 'git-opsmonsters-cred'
} }
} }
stage('Build Docker Image') { stage('Build & Push Docker Image') {
steps { steps {
powershell """ script {
docker build -t ${DOCKERHUB_USER}/${IMAGE_NAME}:${IMAGE_TAG} . withCredentials([usernamePassword(credentialsId: 'dockerhub-credentials', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
""" bat """
} echo %DOCKER_PASS% | docker login -u %DOCKER_USER% --password-stdin
} docker build -t %DOCKER_USER%/%IMAGE_NAME%:%IMAGE_TAG% .
docker push %DOCKER_USER%/%IMAGE_NAME%:%IMAGE_TAG%
stage('Push Image to Docker Hub') { """
steps { }
withCredentials([usernamePassword(credentialsId: 'docker-hub-credentials', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
powershell """
echo $env:DOCKER_PASS | docker login -u $env:DOCKER_USER --password-stdin
docker push ${DOCKERHUB_USER}/${IMAGE_NAME}:${IMAGE_TAG}
"""
} }
} }
} }
stage('Verify Docker Image') {
steps {
bat """
docker images | findstr %DOCKERHUB_USER%/%IMAGE_NAME%
"""
}
}
stage('Deploy to Kubernetes') { stage('Deploy to Kubernetes') {
steps { steps {
powershell """ bat """
kubectl apply -f ${K8S_DEPLOYMENT} kubectl apply -f %DEPLOYMENT_FILE% --validate=false
kubectl apply -f ${K8S_SERVICE} kubectl apply -f %SERVICE_FILE% --validate=false
kubectl get pods -o wide
kubectl get svc
""" """
} }
} }
stage('Verify Deployment') { stage('Verify Deployment') {
steps { steps {
powershell """ bat """
echo Pods Status:
kubectl get pods -o wide kubectl get pods -o wide
echo Services:
kubectl get svc
""" """
} }
} }
} }
post {
success {
echo "Deployment successful!"
}
failure {
echo "Deployment failed. Check logs above."
}
}
} }

View File

@ -14,6 +14,6 @@ spec:
spec: spec:
containers: containers:
- name: myapp - name: myapp
image: IMAGE_PLACEHOLDER # Jenkins will replace this image: vipin2025devops/myapp:latest
ports: ports:
- containerPort: 3000 - containerPort: 3000