Use the following script in your GitHub workflow.
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Import test results to RTM
env:
JOB_URL: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}
RTM_URL: https://your-rtm-instance.com # 1
RTM_API_TOKEN: ${{ secrets.RTM_API_TOKEN }} # 2
PROJECT_KEY: EXAMPLE # 3 target project key with RTM enabled
TE_SUMMARY: Automated tests report build ${{github.run_id}}
run: |
# use tar to create archive with test results
RESULTS_ARCHIVE=test_results.tar.gz
find ./target/surefire-reports -type f -name "*.xml" -exec tar czvf $RESULTS_ARCHIVE {} +
printf "\n[RTM] Importing test results...\n"
IMPORT_RESULT=$(curl -s -S -X POST ${RTM_URL}/api/v2/automation/import-test-results \
-H "Authorization: Bearer ${RTM_API_TOKEN}" \
-F "projectKey=${PROJECT_KEY}" \
-F "name=${TE_SUMMARY}" \
-F "file=@${RESULTS_ARCHIVE}" \
-F 'reportType=JUNIT' \
-F "jobUrl=${JOB_URL}")
# checks in loop import status
if [[ $IMPORT_RESULT =~ ^.{8}-.{4}-.{4}-.{4}-.{12}$ ]]; then
printf "[RTM] Import created with taskId: $IMPORT_RESULT, checking import status"
TASK_STATUS='IMPORTING'
TRIES=0
while [[ "$TASK_STATUS" == *"IMPORTING"* && $TRIES != 30 ]]; do
TASK_STATUS=$(curl -s -S ${RTM_URL}/api/v2/automation/import-status/$IMPORT_RESULT -H "Authorization: Bearer ${RTM_API_TOKEN}")
if [[ "$TASK_STATUS" == *"IMPORTING"* ]]; then
printf "\n[RTM] Importing, retrying in 10 second"
sleep 10s
fi
((TRIES = TRIES + 1))
done
if [ $TRIES -gt 30 ]; then
printf "\n[RTM] Import timeout with last status: ${TASK_STATUS}\n"
else
printf "\n[RTM] Import completed with status: ${TASK_STATUS}\n"
fi
else
printf "\n[RTM] Import failed with response: ${IMPORT_RESULT}\n"
fi
See REST API for all available options to import endpoint.