From c7a98bcf020389c7d025c9a3e512d271a9e3427d Mon Sep 17 00:00:00 2001 From: Matt Reeves Date: Mon, 2 Dec 2024 20:02:41 -0500 Subject: [PATCH] add log logic to cd --- .forgejo/workflows/CD.yml | 43 +++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/.forgejo/workflows/CD.yml b/.forgejo/workflows/CD.yml index d70cec5..bcd4261 100644 --- a/.forgejo/workflows/CD.yml +++ b/.forgejo/workflows/CD.yml @@ -94,20 +94,33 @@ jobs: "https://awx.mafyuh.xyz/api/v2/job_templates/13/launch/" > /dev/null 2>&1 echo "AWX Job Triggered, waiting for logs..." - sleep 45 + # Wait for job completion and check logs + while true; do + # Fetch the most recent job ID + job_id=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \ + https://awx.mafyuh.xyz/api/v2/job_templates/13/jobs/?order_by=-id | jq -r '.results[0].id') + + # Fetch the logs for the current job + logs=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \ + https://awx.mafyuh.xyz/api/v2/jobs/$job_id/stdout/?format=txt) - job_id=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/job_templates/13/jobs/?order_by=-id | jq -r '.results[0].id') - logs=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/jobs/$job_id/stdout/?format=txt) + # Check if the logs contain the play recap + if echo "$logs" | grep -q "ok=.* changed=.* unreachable=.* failed=.* skipped=.* rescued=.* ignored=.*"; then + echo "AWX job completed. Displaying logs:" + echo "$logs" + + # Check for failed tasks in the play recap + if echo "$logs" | grep -q "failed=[1-9]"; then + echo "Detected failed steps in AWX job. Failing Actions run." + exit 1 + else + echo "No failures detected in AWX job." + fi - echo "AWX Job Logs for folder: $folder" - echo "Content:" - echo "$logs" - - # Check for 'failed=' in the play recap - if echo "$logs" | grep -q "failed=[1-9]"; then - echo "Detected failed steps in AWX job. Failing Actions run." - exit 1 - else - echo "No failures detected in AWX job." - fi - done + # Exit loop as the job is complete + break + else + echo "AWX job still running. Waiting before checking again..." + sleep 15 + fi + done