stages:
- test
qodex:
stage: test
image: alpine:3.20
timeout: 30m
before_script:
- apk add --no-cache curl jq
script:
- |
ENV_NAME=staging
if [ "$CI_COMMIT_REF_NAME" = "main" ]; then ENV_NAME=prod; fi
RESPONSE=$(curl -fsS -X POST \
"https://agents.qodex.ai/api/projects/${QODEX_PROJECT}/webhooks/trigger" \
-H "Authorization: Bearer ${QODEX_API_KEY}" \
-H "Content-Type: application/json" \
-d "{\"environment\":\"${ENV_NAME}\",\"tags\":[\"smoke\"]}")
RUN_ID=$(echo "$RESPONSE" | jq -r .testRunId)
if [ -z "$RUN_ID" ] || [ "$RUN_ID" = "null" ]; then
echo "Failed to start run. Response: $RESPONSE"
exit 1
fi
DEADLINE=$(( $(date +%s) + 1500 ))
while [ "$(date +%s)" -lt "$DEADLINE" ]; do
STATUS=$(curl -fsS \
"https://agents.qodex.ai/api/projects/${QODEX_PROJECT}/test-runs/${RUN_ID}" \
-H "Authorization: Bearer ${QODEX_API_KEY}" | jq -r .status)
echo "status=$STATUS"
case "$STATUS" in
completed) exit 0 ;;
failed) exit 1 ;;
*) sleep 10 ;;
esac
done
echo "Timed out waiting for Qodex run ${RUN_ID}"
exit 1
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == "main"'