Eric O.
Eric O.

Reputation: 583

How to upload pytest report to Gitlab Ci

I have a repo of a Django app on Gitlab. The app is deployed to an Azure Linux Instance. I can't seem to get the pytest reports visible on the GitLab CI despite all the combinations I have tried. The problem lies around me not clearly knowing how GitLab gets files created by pytest running inside an ssh session.

Please note I have left out some unnecessary details below: Here is my pytest.ini

[pytest]
addopts = --junitxml=report.xml

Here is my gitlab-ci.yml script and artifacts section

script:
    - ssh [email protected] "cd /home/eric/www/uat/eric-portal; /home/eric/.virtualenvs/eric-uat/bin/pytest"

artifacts:
    when: always
    paths:
      - /builds/my-company/eric/eric-portal/report.xml
      - report.xml
      - ./report.xml
      - /home/eric/www/uat/eric-portal/report.xml
      - eric-portal/report.xml
    reports:
      junit:
        - /builds/my-company/eric/eric-portal/report.xml
        - report.xml
        - ./report.xml
        - /home/eric/www/uat/eric-portal/report.xml
        - eric-portal/report.xml

Here is part of what is generated during the test stage

----- generated xml file: /home/eric/www/uat/eric-portal/report.xml ------
======================== 1 passed, 2 warnings in 1.24s =========================
Uploading artifacts for successful job
00:01
Uploading artifacts...
WARNING: /builds/my-company/eric/eric-portal/report.xml: no matching files 
WARNING: report.xml: no matching files             
WARNING: ./report.xml: no matching files           
WARNING: /home/eric/www/uat/eric-portal/report.xml: no matching files 
WARNING: eric-portal/report.xml: no matching files 
ERROR: No files to upload                          
Uploading artifacts...
WARNING: /builds/my-company/eric/eric-portal/report.xml: no matching files 
WARNING: report.xml: no matching files             
WARNING: ./report.xml: no matching files           
WARNING: /home/eric/www/uat/eric-portal/report.xml: no matching files 
WARNING: eric-portal/report.xml: no matching files 
ERROR: No files to upload  

/builds/my-company/eric/eric-portal/report.xml is what I get when I run readlink -f report.xml immediately after the pytest script

I would also love some advice on whether this is an efficient way of setting up CI for testing a Django app (I have 3 stages: build, test,and deploy and all happen in ssh session). I am currently running the tests on the server. Is there a way to run the tests on GitLab without SSHing into my server?

Upvotes: 1

Views: 2159

Answers (1)

Lior Pollak
Lior Pollak

Reputation: 3450

Consider doing all the ci in gitlab runners- build and test.
You can build an image using kaniko inside the runner.
Then your tests would run directly on the runner, and the runner will have access to the output.
The deploy can also be done from the runner- assuming you uploaded your docker image to a registry, it is a matter of pulling and running the image in your cluster.

Upvotes: 0

Related Questions