Update apps/demo-nginx/Jenkinsfile

This commit is contained in:
2026-01-08 10:53:22 +00:00
parent bbdf1f60b0
commit 5e483cbcdd

View File

@@ -289,80 +289,43 @@ EOF
} }
stage('Wait for ArgoCD Sync') { stage('Wait for ArgoCD Sync') {
when { branch 'main' } steps {
steps { script {
script { echo "⏳ Waiting for ArgoCD to apply Git revision..."
echo "⏳ Waiting for ArgoCD to sync Git manifests..."
sendTelegramNotification( def expectedRevision = sh(
status: 'SYNCING', script: "git rev-parse HEAD",
message: """ returnStdout: true
⏳ <b>ArgoCD Syncing</b> ).trim()
<b>Application:</b> ${APP_NAME} for (int i = 1; i <= 12; i++) {
<b>Namespace:</b> argocd def argoRevision = sh(
<b>Timeout:</b> ${ARGOCD_SYNC_TIMEOUT}s script: "kubectl get application demo-nginx -n argocd -o jsonpath='{.status.sync.revision}'",
""", returnStdout: true
color: '🔵' ).trim()
)
def syncSuccess = false def syncStatus = sh(
def attempts = 0 script: "kubectl get application demo-nginx -n argocd -o jsonpath='{.status.sync.status}'",
def maxAttempts = Integer.parseInt(env.ARGOCD_SYNC_TIMEOUT) / 10 returnStdout: true
).trim()
while (!syncSuccess && attempts < maxAttempts) { echo "Expected Git revision : ${expectedRevision}"
attempts++ echo "ArgoCD applied revision: ${argoRevision}"
echo "ArgoCD sync check attempt ${attempts}/${maxAttempts}..." echo "ArgoCD sync status : ${syncStatus}"
def syncStatus = sh( if (syncStatus == "Synced" && argoRevision == expectedRevision) {
script: """ echo "✅ ArgoCD successfully applied Git revision"
kubectl get application ${APP_NAME} -n argocd \ return
-o jsonpath='{.status.sync.status}'
""",
returnStdout: true
).trim()
def healthStatus = sh(
script: """
kubectl get application ${APP_NAME} -n argocd \
-o jsonpath='{.status.health.status}'
""",
returnStdout: true
).trim()
def deploymentImage = sh(
script: """
kubectl get deployment ${APP_NAME} -n ${NAMESPACE} \
-o jsonpath='{.spec.template.spec.containers[0].image}'
""",
returnStdout: true
).trim()
echo "ArgoCD sync status: ${syncStatus}"
echo "ArgoCD health status: ${healthStatus}"
echo "Deployment spec image: ${deploymentImage}"
echo "Expected image tag: ${IMAGE_TAG}"
// Check if ArgoCD applied the manifest AND deployment spec is updated
if (syncStatus == 'Synced' && deploymentImage.contains(env.IMAGE_TAG)) {
syncSuccess = true
echo "✅ ArgoCD synced and deployment spec updated!"
echo "Note: Pods may still be rolling out - will verify in next stage"
break
}
if (attempts < maxAttempts) {
echo "Waiting 10 seconds before next check..."
sleep 10
}
}
if (!syncSuccess) {
error "❌ ArgoCD sync timeout! Deployment spec was not updated with new image."
}
} }
sleep 10
} }
error("❌ ArgoCD did not apply expected Git revision in time")
} }
}
}
stage('Wait for Deployment') { stage('Wait for Deployment') {
when { branch 'main' } when { branch 'main' }