Update apps/demo-nginx/Jenkinsfile

This commit is contained in:
2026-01-08 14:28:39 +00:00
parent 58fd9df43d
commit 45f23ac0f3

View File

@@ -398,57 +398,67 @@ EOF
} }
stage('Verify Deployment') { stage('Verify Deployment') {
when { branch 'main' } when { branch 'main' }
steps { steps {
script { script {
echo "✅ Verifying deployment and pod status..." echo "✅ Verifying deployment and pod status..."
try { /* -------------------------------
def verifyResult = sh(script: """#!/bin/bash * 1. Deployment status check
set -e * ------------------------------- */
sh """
set -e
echo "================================================"
echo "DEPLOYMENT VERIFICATION"
echo "================================================"
echo "================================================" echo ""
echo "DEPLOYMENT VERIFICATION" echo "1. Checking deployment status..."
echo "================================================"
# 1. Check deployment status READY_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.readyReplicas}')
echo "" DESIRED_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.spec.replicas}')
echo "1. Checking deployment status..." UPDATED_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.updatedReplicas}')
READY_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.readyReplicas}') AVAILABLE_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.availableReplicas}')
DESIRED_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.spec.replicas}')
UPDATED_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.updatedReplicas}')
AVAILABLE_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.availableReplicas}')
echo " Desired replicas: \${DESIRED_PODS}" echo " Desired replicas : \$DESIRED_PODS"
echo " Updated replicas: \${UPDATED_PODS}" echo " Updated replicas : \$UPDATED_PODS"
echo " Ready replicas: \${READY_PODS}" echo " Ready replicas : \$READY_PODS"
echo " Available replicas: \${AVAILABLE_PODS}" echo " Available replicas : \$AVAILABLE_PODS"
if [ "\${READY_PODS}" != "\${DESIRED_PODS}" ]; then if [ "\$READY_PODS" != "\$DESIRED_PODS" ]; then
echo " ❌ FAILED: Not all pods are ready!" echo "❌ FAILED: Not all pods are ready"
echo " Expected: \${DESIRED_PODS}, Got: \${READY_PODS}" exit 1
exit 1 fi
fi
echo " ✅ All pods ready"
# 2. Verify running pod images echo "✅ All pods are ready"
echo "" """
echo "2. Checking running pod images..."
def POD_IMAGES = sh( /* -------------------------------
script: "kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME} -o jsonpath='{range .items[*]}{.spec.containers[0].image}{\" \"}{end}'", * 2. Pod image verification (Groovy!)
returnStdout: true * ------------------------------- */
).trim() def podImages = sh(
script: """
kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME} \
-o jsonpath='{range .items[*]}{.spec.containers[0].image}{"\\n"}{end}'
""",
returnStdout: true
).trim()
echo " Running pod images:" echo ""
echo " ${POD_IMAGES}" echo "2. Checking running pod images..."
echo " Expected tag: ${IMAGE_TAG}" echo "Running pod images:"
echo podImages
echo "Expected image tag: ${IMAGE_TAG}"
if (!POD_IMAGES.contains(IMAGE_TAG)) { if (!podImages.contains(IMAGE_TAG)) {
error("❌ FAILED: Running pods do not use expected image!") error("❌ FAILED: Running pods do not use expected image ${IMAGE_TAG}")
} }
echo "✅ All running pods use expected image ${IMAGE_TAG}"
}
}
}
echo " ✅ All running pods use expected image"