Update apps/demo-nginx/Jenkinsfile

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

View File

@@ -403,52 +403,62 @@ EOF
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
* ------------------------------- */
sh """
set -e set -e
echo "================================================" echo "================================================"
echo "DEPLOYMENT VERIFICATION" echo "DEPLOYMENT VERIFICATION"
echo "================================================" echo "================================================"
# 1. Check deployment status
echo "" echo ""
echo "1. Checking deployment status..." echo "1. Checking deployment status..."
READY_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.readyReplicas}') READY_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.status.readyReplicas}')
DESIRED_PODS=\$(kubectl get deployment ${APP_NAME} -n ${NAMESPACE} -o jsonpath='{.spec.replicas}') 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}') 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}') 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!)
* ------------------------------- */
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 returnStdout: true
).trim() ).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" echo "✅ All running pods use expected image ${IMAGE_TAG}"
}
}
}