diff --git a/templates/testreport/diff.yml b/templates/testreport/diff.yml
index 4b72ae0a4e124020e52c5964d87c581fcc06abf7..280b99566527a63784bceab77c3ac5a41835c90a 100644
--- a/templates/testreport/diff.yml
+++ b/templates/testreport/diff.yml
@@ -10,8 +10,21 @@
     - if: $CI_AWE_RUN_TEST_REPORT_DIFF
     - !reference [.primary_ref_jobs, rules]
   script:
+    # To download the test report of the previous pipeline, we cannot use the API
+    # as described at https://docs.gitlab.com/ee/api/job_artifacts.html#download-a-single-artifact-file-from-specific-tag-or-branch,
+    # because that only exposes the latest _successful_ pipeline. We want the latest test report
+    # of either the last succeeded pipeline or the last failed pipeline.
+    # So, first determine the previous pipeline.
+    - LAST_PIPELINE_SUCCESS=$(gitlab --output json project-pipeline list --project-id $CI_PROJECT_ID --ref $TEST_REPORT_DIFF_REF --scope finished --status success | jq 'first.id')
+    - LAST_PIPELINE_FAILED=$(gitlab --output json project-pipeline list --project-id $CI_PROJECT_ID --ref $TEST_REPORT_DIFF_REF --scope finished --status failed | jq 'first.id')
+    - LAST_PIPELINE=$(( LAST_PIPELINE_SUCCESS > LAST_PIPELINE_FAILED ? LAST_PIPELINE_SUCCESS : LAST_PIPELINE_FAILED ))
+    - echo "Previous pipeline on ${TEST_REPORT_DIFF_REF} was ${LAST_PIPELINE}."
+    # Determine the previous job.
+    - LAST_JOB=$(gitlab --output json project-pipeline-job list --project-id $CI_PROJECT_ID --pipeline-id $LAST_PIPELINE | jq ".[] | select(.name==\"${TEST_REPORT_JOB}\") | .id")
+    - echo "Previous ${TEST_REPORT_JOB} job was ${LAST_JOB}."
     # Download the report of the previous pipeline.
-    - TEST_REPORT_ARTIFACT_URL="$CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/artifacts/$TEST_REPORT_DIFF_REF/raw/$TEST_REPORT_ARTIFACT_FILE?job=$TEST_REPORT_JOB"
+    # Can't use python-gitlab for that yet, see https://github.com/python-gitlab/python-gitlab/issues/1926.
+    - TEST_REPORT_ARTIFACT_URL="$CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/$LAST_JOB/artifacts/$TEST_REPORT_ARTIFACT_FILE"
     - 'curl --output "$TEST_REPORT_ARTIFACT_FILE.old" --location --header "JOB-TOKEN: $CI_JOB_TOKEN" "$TEST_REPORT_ARTIFACT_URL"'
     # Compare it to the report of this pipeline.
     - report_diff "$TEST_REPORT_ARTIFACT_FILE.old" "$TEST_REPORT_ARTIFACT_FILE" report_diff.xml