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 {
echo "✅ Verifying deployment and pod status..."
try {
def verifyResult = sh(script: """#!/bin/bash
/* -------------------------------
* 1. Deployment status check
* ------------------------------- */
sh """
set -e
echo "================================================"
echo "DEPLOYMENT VERIFICATION"
echo "================================================"
# 1. Check deployment status
echo ""
echo "1. Checking deployment status..."
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}')
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 " Updated replicas: \${UPDATED_PODS}"
echo " Ready replicas: \${READY_PODS}"
echo " Available replicas: \${AVAILABLE_PODS}"
echo " Desired replicas : \$DESIRED_PODS"
echo " Updated replicas : \$UPDATED_PODS"
echo " Ready replicas : \$READY_PODS"
echo " Available replicas : \$AVAILABLE_PODS"
if [ "\${READY_PODS}" != "\${DESIRED_PODS}" ]; then
echo " ❌ FAILED: Not all pods are ready!"
echo " Expected: \${DESIRED_PODS}, Got: \${READY_PODS}"
if [ "\$READY_PODS" != "\$DESIRED_PODS" ]; then
echo "❌ FAILED: Not all pods are ready"
exit 1
fi
echo " ✅ All pods ready"
# 2. Verify running pod images
echo ""
echo "2. Checking running pod images..."
echo "✅ All pods are ready"
"""
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
).trim()
echo " Running pod images:"
echo " ${POD_IMAGES}"
echo " Expected tag: ${IMAGE_TAG}"
echo ""
echo "2. Checking running pod images..."
echo "Running pod images:"
echo podImages
echo "Expected image tag: ${IMAGE_TAG}"
if (!POD_IMAGES.contains(IMAGE_TAG)) {
error("❌ FAILED: Running pods do not use expected image!")
if (!podImages.contains(IMAGE_TAG)) {
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}"
}
}
}