@@ -94,20 +94,33 @@ jobs:
94
94
"https://awx.mafyuh.xyz/api/v2/job_templates/13/launch/" > /dev/null 2>&1
95
95
echo "AWX Job Triggered, waiting for logs..."
96
96
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)
98
106
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
101
119
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