I am trying to generate test reports via pipeline. Html is generated and I am able to access the Gitlab page for the same. However the issue arises if a new pipeline (or even if a job) is triggered, test report is generated and the previous one gives 404 error. (URLs are different)
i.e for eg: example.gitlab.io/project/{CI_PIPELINE_ID}/ or {CI_JOB_ID}
The use case is that this does not give me an option to compare between test reports.
A solution was to cache the public folder and then I am able to access different versions of the test in their respective URLs.
However I am new to this and I am not sure if that is correct for I have to clear the cache manually which I believe is only available to the maintainers and owners of the project.
Is there any other way to preserve the Gitlab pages from the previous pipelines?
P.S: I am new to this
Edit: Adding a sample gitlab-ci.yml file for reference:
stages:
- build
pages:
image: cypress/base:10
stage: build
script:
- npm ci
- npx cypress run
after_script:
# Generate report using mochaswesome-merge
# Combine different json files into single json file
- npx mochawesome-merge cypress/reporters/json/*.json > cypress/reporters/output.json
# Generate html from the json file using marge. Eache new html is created inside a new folder based on timeline.
- npx marge cypress/reporters/output.json -f cypress/reporters/$(date +"%Y%m%d-%Ih%Mm") -o ./ --inline
# Make a public folder for the gitlab page to be created
- mkdir -p public
- mkdir -p public/$(date +"%Y%m%d-%Ih%Mm")/
# Moving the contents of the report folder inside a public under the same folder name as the report
- mv cypress/reporters/* public/$(date +"%Y%m%d-%Ih%Mm")/
#Creating an index html that will have the file listing of all the generated reports
- cd public
- echo "<html><body><h1>File listing:</h1>" > ./index.html
- find -iname '*.html' -execdir echo "<a href='{}'>{}</a><br><br/>" \; >> ./index.html
- echo "</body></html>" >> ./index.html
when: always
only:
- dev
#Cache is required so that we have the report folder created from each pipeline. This allows us to list the files in the index html.
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- public
#Artifact of each pipeline. Contains report of that particular pipeline.
artifacts:
name: "$CI_JOB_ID"
expire_in: 1 day
when: always
paths:
- public