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') {
when { branch 'main' }
steps {
script {
echo "⏳ Waiting for ArgoCD to sync Git manifests..."
echo "⏳ Waiting for ArgoCD to apply Git revision..."
sendTelegramNotification(
status: 'SYNCING',
message: """
⏳ <b>ArgoCD Syncing</b>
def expectedRevision = sh(
script: "git rev-parse HEAD",
returnStdout: true
).trim()
<b>Application:</b> ${APP_NAME}
<b>Namespace:</b> argocd
<b>Timeout:</b> ${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}..."
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 ${APP_NAME} -n argocd \
-o jsonpath='{.status.sync.status}'
""",
script: "kubectl get application demo-nginx -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()
echo "Expected Git revision : ${expectedRevision}"
echo "ArgoCD applied revision: ${argoRevision}"
echo "ArgoCD sync status : ${syncStatus}"
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 (syncStatus == "Synced" && argoRevision == expectedRevision) {
echo "✅ ArgoCD successfully applied Git revision"
return
}
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."
}
}
error("❌ ArgoCD did not apply expected Git revision in time")
}
}
}
stage('Wait for Deployment') {
when { branch 'main' }