Nom du fichier : Sans nom
upload_to_jira_xray:
stage: reporting
needs: ["playwright_e2e_tests"]
before_script: []
script:
- set -x
- echo "===> Importing results to XRAY-JIRA..."
- |
JUNIT_REPORT="test-results/junit-report.xml"
# Vérifier que le fichier existe et n'est pas vide
if [ ! -s "$JUNIT_REPORT" ]; then
echo "JUnit report non trouvé ou vide à: $JUNIT_REPORT"
ls -la test-results/ || true
exit 1
fi
echo "JUnit Report trouvé: $(wc -c < "$JUNIT_REPORT") octets"
echo "------- CONTENU JUNIT REPORT -------"
cat "${JUNIT_REPORT}"
echo "-------------------------------------"
# Correction éventuelle des balises <failure>
sed -i '/<failure/ s/$/"\/>/' "$JUNIT_REPORT"
grep -C 5 "failure" "$JUNIT_REPORT" || echo "Aucune balise <failure>, pas de correction nécessaire"
# Timestamp Paris
TIMESTAMP=$(TZ="Europe/Paris" date +"%Y-%m-%d %H:%M")
echo "Timestamp: $TIMESTAMP"
echo "Projet: ${XRAY_PROJECT_KEY}"
echo "Plan de test: ${XRAY_TEST_PLAN_KEY}"
# Construction du info.json avec les variables du CI
INFO_JSON=$(printf '{
"fields": {
"project": {"key": "%s"},
"summary": "Execution Results DCU-V2 [%s]",
"issuetype": {"name": "Test Execution"}
},
"xrayFields": {
"testPlanKey": "%s"
}
}' "${XRAY_PROJECT_KEY}" "$TIMESTAMP" "${XRAY_TEST_PLAN_KEY}")
echo "JSON info: $INFO_JSON"
echo "$INFO_JSON" > info.json
echo "===> UPLOAD VERS XRAY ==> "
HTTP_RESPONSE=$(curl -s -w "\n%{http_code}" \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer ${TOKEN}" \
-F "info=@info.json;type=application/json" \
-F "results=@${JUNIT_REPORT};type=application/xml" \
"https://xray.cloud.getxray.app/api/v2/import/execution/junit/multipart?projectKey=${XRAY_PROJECT_KEY}")
- set +x
- |
HTTP_CODE=${HTTP_RESPONSE: -3}
BODY=${HTTP_RESPONSE::-3}
echo "HTTP Code : $HTTP_CODE"
echo "Response : $BODY"
if [ "$HTTP_CODE" != "200" ] && [ "$HTTP_CODE" != "201" ]; then
echo "Erreur lors de l'import vers Xray (HTTP $HTTP_CODE)"
exit 1
fi
echo "Importation reussie dans Xray!"
allow_failure: false
artifacts:
when: always
expire_in: 1 day
paths:
- test-results/
- test-results/junit-report.xml
- info.json