From 06e20d8762688cf969b640dad52c42abaa0c8793 Mon Sep 17 00:00:00 2001 From: Teake Nutma <t.a.nutma@rug.nl> Date: Thu, 16 Jun 2022 16:40:45 +0200 Subject: [PATCH] Compare testreport of previous pipeline, not previous successfull pipeline --- templates/testreport/diff.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/templates/testreport/diff.yml b/templates/testreport/diff.yml index 4b72ae0..280b995 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 -- GitLab