Update apps/demo-nginx/Jenkinsfile
This commit is contained in:
77
apps/demo-nginx/Jenkinsfile
vendored
77
apps/demo-nginx/Jenkinsfile
vendored
@@ -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 sync Git manifests..."
|
echo "⏳ Waiting for ArgoCD to apply Git revision..."
|
||||||
|
|
||||||
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 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(
|
def syncStatus = sh(
|
||||||
script: """
|
script: "kubectl get application demo-nginx -n argocd -o jsonpath='{.status.sync.status}'",
|
||||||
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
|
returnStdout: true
|
||||||
).trim()
|
).trim()
|
||||||
|
|
||||||
|
echo "Expected Git revision : ${expectedRevision}"
|
||||||
|
echo "ArgoCD applied revision: ${argoRevision}"
|
||||||
echo "ArgoCD sync status : ${syncStatus}"
|
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" && argoRevision == expectedRevision) {
|
||||||
if (syncStatus == 'Synced' && deploymentImage.contains(env.IMAGE_TAG)) {
|
echo "✅ ArgoCD successfully applied Git revision"
|
||||||
syncSuccess = true
|
return
|
||||||
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
|
sleep 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error("❌ ArgoCD did not apply expected Git revision in time")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!syncSuccess) {
|
|
||||||
error "❌ ArgoCD sync timeout! Deployment spec was not updated with new image."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Wait for Deployment') {
|
stage('Wait for Deployment') {
|
||||||
when { branch 'main' }
|
when { branch 'main' }
|
||||||
|
|||||||
Reference in New Issue
Block a user