diff --git a/apps/demo-nginx/Jenkinsfile b/apps/demo-nginx/Jenkinsfile index 73bc780..a273180 100644 --- a/apps/demo-nginx/Jenkinsfile +++ b/apps/demo-nginx/Jenkinsfile @@ -289,80 +289,43 @@ EOF } stage('Wait for ArgoCD Sync') { - when { branch 'main' } - steps { - script { - echo "⏳ Waiting for ArgoCD to sync Git manifests..." - - sendTelegramNotification( - status: 'SYNCING', - message: """ -⏳ ArgoCD Syncing + steps { + script { + echo "⏳ Waiting for ArgoCD to apply Git revision..." -Application: ${APP_NAME} -Namespace: argocd -Timeout: ${ARGOCD_SYNC_TIMEOUT}s - """, - color: '🔵' - ) - - def syncSuccess = false - def attempts = 0 - def maxAttempts = Integer.parseInt(env.ARGOCD_SYNC_TIMEOUT) / 10 - - while (!syncSuccess && attempts < maxAttempts) { - attempts++ - echo "ArgoCD sync check attempt ${attempts}/${maxAttempts}..." - - def syncStatus = sh( - script: """ - kubectl get application ${APP_NAME} -n argocd \ - -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." - } + def expectedRevision = sh( + script: "git rev-parse HEAD", + returnStdout: true + ).trim() + + for (int i = 1; i <= 12; i++) { + def argoRevision = sh( + script: "kubectl get application demo-nginx -n argocd -o jsonpath='{.status.sync.revision}'", + returnStdout: true + ).trim() + + def syncStatus = sh( + script: "kubectl get application demo-nginx -n argocd -o jsonpath='{.status.sync.status}'", + returnStdout: true + ).trim() + + echo "Expected Git revision : ${expectedRevision}" + echo "ArgoCD applied revision: ${argoRevision}" + echo "ArgoCD sync status : ${syncStatus}" + + if (syncStatus == "Synced" && argoRevision == expectedRevision) { + echo "✅ ArgoCD successfully applied Git revision" + return } + + sleep 10 } + + error("❌ ArgoCD did not apply expected Git revision in time") } + } +} + stage('Wait for Deployment') { when { branch 'main' }