Update apps/demo-nginx/Jenkinsfile

This commit is contained in:
2026-01-08 10:02:50 +00:00
parent df69ad65f8
commit 75931b7bcc

View File

@@ -440,10 +440,9 @@ EOF
when { branch 'main' }
steps {
script {
echo "✅ Verifying deployment and pod status..."
echo " Verifying deployment and pod status..."
try {
def verifyResult = sh(script: """#!/bin/bash
sh '''#!/bin/bash
set -e
echo "================================================"
@@ -453,27 +452,28 @@ EOF
# 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}"
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}')
if [ "\${READY_PODS}" != "\${DESIRED_PODS}" ]; then
echo " ❌ FAILED: Not all pods are ready!"
echo " Expected: \${DESIRED_PODS}, Got: \${READY_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}"
exit 1
fi
echo " ✅ All pods ready"
echo " All pods ready"
# 2. Verify pod images (source of truth)
echo ""
echo "2. Checking running pod images..."
POD_IMAGES=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \
-o jsonpath='{.items[*].spec.containers[0].image}')
@@ -486,67 +486,67 @@ EOF
fi
echo " ✅ All pods are running expected image"
# 3. CRITICAL: Verify actual running pod images
echo ""
echo "3. Checking actual running pod images..."
POD_IMAGES=\$(kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME} -o jsonpath='{range .items[*]}{.status.containerStatuses[0].image}{"\\n"}{end}')
POD_IMAGES=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \
-o jsonpath='{range .items[*]}{.status.containerStatuses[0].image}{"\n"}{end}')
echo " Running pod images:"
echo "\${POD_IMAGES}" | while read -r img; do
echo " - \${img}"
done
# Check if all pods are running the correct image
WRONG_IMAGE_COUNT=0
while IFS= read -r img; do
if [[ "\${img}" != *"${IMAGE_TAG}"* ]]; then
echo " ❌ Pod running wrong image: \${img}"
WRONG_IMAGE_COUNT=\$((WRONG_IMAGE_COUNT + 1))
fi
done <<< "\${POD_IMAGES}"
if [ \${WRONG_IMAGE_COUNT} -gt 0 ]; then
echo " ❌ FAILED: \${WRONG_IMAGE_COUNT} pod(s) running old image!"
echo " This is the ArgoCD sync bug - deployment updated but pods not rolled out"
while read -r img; do
echo " - ${img}"
if [[ "${img}" != *"${IMAGE_TAG}"* ]]; then
echo " ❌ Pod running wrong image: ${img}"
exit 1
fi
echo " ✅ All pods running correct image"
done <<< "${POD_IMAGES}"
echo " ✅ All pods running correct image"
# 4. Check pod readiness
echo ""
echo "4. Checking pod readiness probes..."
NOT_READY=\$(kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME} --field-selector=status.phase!=Running --no-headers 2>/dev/null | wc -l)
echo "4. Checking pod readiness..."
if [ "\${NOT_READY}" -gt 0 ]; then
echo " ⚠️ WARNING: \${NOT_READY} pod(s) not in Running state"
kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME}
NOT_READY=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \
--field-selector=status.phase!=Running --no-headers 2>/dev/null | wc -l)
if [ "${NOT_READY}" -gt 0 ]; then
echo " ⚠️ WARNING: ${NOT_READY} pod(s) not in Running state"
kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}"
else
echo " ✅ All pods in Running state"
echo " All pods in Running state"
fi
# 5. Check container restart count
echo ""
echo "5. Checking for container restarts..."
RESTART_COUNTS=\$(kubectl get pods -n ${NAMESPACE} -l app=${APP_NAME} -o jsonpath='{range .items[*]}{.status.containerStatuses[0].restartCount}{"\\n"}{end}')
MAX_RESTARTS=0
while IFS= read -r count; do
if [ "\${count}" -gt "\${MAX_RESTARTS}" ]; then
MAX_RESTARTS=\${count}
fi
done <<< "\${RESTART_COUNTS}"
echo " Max restart count: \${MAX_RESTARTS}"
if [ "\${MAX_RESTARTS}" -gt 3 ]; then
echo " ⚠️ WARNING: High restart count detected"
RESTART_COUNTS=$(kubectl get pods -n "${NAMESPACE}" -l app="${APP_NAME}" \
-o jsonpath='{range .items[*]}{.status.containerStatuses[0].restartCount}{"\n"}{end}')
MAX_RESTARTS=0
while read -r count; do
if [ "${count}" -gt "${MAX_RESTARTS}" ]; then
MAX_RESTARTS="${count}"
fi
done <<< "${RESTART_COUNTS}"
echo " Max restart count: ${MAX_RESTARTS}"
if [ "${MAX_RESTARTS}" -gt 3 ]; then
echo " ⚠️ WARNING: High restart count detected"
else
echo " ✅ Restart count acceptable"
echo " Restart count acceptable"
fi
echo ""
echo "================================================"
echo "✅ ALL VERIFICATION CHECKS PASSED!"
echo " ALL VERIFICATION CHECKS PASSED!"
echo "================================================"
'''
}
""", returnStdout: true).trim()
echo verifyResult