Skip to content

Commit c7a98bc

Browse files
committedDec 3, 2024
add log logic to cd
1 parent cd7b074 commit c7a98bc

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed
 

‎.forgejo/workflows/CD.yml

+28-15
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,33 @@ jobs:
9494
"https://awx.mafyuh.xyz/api/v2/job_templates/13/launch/" > /dev/null 2>&1
9595
echo "AWX Job Triggered, waiting for logs..."
9696
97-
sleep 45
97+
# Wait for job completion and check logs
98+
while true; do
99+
# Fetch the most recent job ID
100+
job_id=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \
101+
https://awx.mafyuh.xyz/api/v2/job_templates/13/jobs/?order_by=-id | jq -r '.results[0].id')
102+
103+
# Fetch the logs for the current job
104+
logs=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \
105+
https://awx.mafyuh.xyz/api/v2/jobs/$job_id/stdout/?format=txt)
98106
99-
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')
100-
logs=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/jobs/$job_id/stdout/?format=txt)
107+
# Check if the logs contain the play recap
108+
if echo "$logs" | grep -q "ok=.* changed=.* unreachable=.* failed=.* skipped=.* rescued=.* ignored=.*"; then
109+
echo "AWX job completed. Displaying logs:"
110+
echo "$logs"
111+
112+
# Check for failed tasks in the play recap
113+
if echo "$logs" | grep -q "failed=[1-9]"; then
114+
echo "Detected failed steps in AWX job. Failing Actions run."
115+
exit 1
116+
else
117+
echo "No failures detected in AWX job."
118+
fi
101119
102-
echo "AWX Job Logs for folder: $folder"
103-
echo "Content:"
104-
echo "$logs"
105-
106-
# Check for 'failed=' in the play recap
107-
if echo "$logs" | grep -q "failed=[1-9]"; then
108-
echo "Detected failed steps in AWX job. Failing Actions run."
109-
exit 1
110-
else
111-
echo "No failures detected in AWX job."
112-
fi
113-
done
120+
# Exit loop as the job is complete
121+
break
122+
else
123+
echo "AWX job still running. Waiting before checking again..."
124+
sleep 15
125+
fi
126+
done

0 commit comments

Comments
 (0)
Please sign in to comment.