9

I am deploying Django application using Gitlab CI/CD and pytest for testing of code and pytest-cov for generating coverage report

My .gitlab-ci.yml

stages:
  - test
  - deploy

image: python:3.6

test:
  stage: test
  script:
    - pip install pipenv
    - pipenv install
    - pipenv run py.test src/
  artifacts:
    paths:
      - htmlcov/

pages:
  stage: deploy
  dependencies:
    - test
  script:
    - mv htmlcov/ public/
  artifacts:
    paths:
      - public
    expire_in: 30 days
  only:
    - master

staging:
  stage: deploy
  script:
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
    - dpl --provider=heroku --app=app-staging --api-key=$HEROKU_PRODUCTION_API_KEY
  only:
    - master

production:
  stage: deploy
  script:
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
    - dpl --provider=heroku --app=app-production --api-key=$HEROKU_PRODUCTION_API_KEY
  when: manual
  only:
    - master

Since repository is under a group namespace, the url to the coverage report is

https://<group>.gitlab.io/<repository>/

For coverage report,

[![coverage report](https://gitlab.com/<group>/<repository>/badges/master/coverage.svg?job=coverage)](https://<group>.gitlab.io/<repository>/)

But this is displaying Unknown

enter image description here

I have setup Test Coverage parsing regex for python

enter image description here

Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
  • What GitLab version are you using? That was supposed to be fixed in 8.15: https://gitlab.com/gitlab-org/gitlab-ce/issues/26151. Or 9.1.4: https://gitlab.com/gitlab-org/gitlab-ce/issues/35552#note_36082521 – VonC Jul 08 '18 at 04:37
  • I'm using Gitlab.com so probably it will be the latest version – Anuj TBE Jul 08 '18 at 08:06
  • did you fix this? – Fran_gg7 Oct 07 '19 at 09:03

2 Answers2

5

I know this is an old question, but this may help others see this question in the future. Except setting the Test Coverage parsing regex in the Settings, CI/CD page, you need to make sure the test coverage percent is printed somewhere in the CI's console log. The printed line should match the given regex. So, Gitlab can parse and save it as the code coverage percent.

I've answered with more detail the same question: Gitlab coverage badge always unknow

Reza Ebrahimpour
  • 814
  • 6
  • 20
2

Your regex works for me in Gitlab.

I've had similar problems though, because just rerunning a job does not pick up new settings, and so you need to do a fresh commit to get the coverage to show up in the job output.

kmt
  • 773
  • 12
  • 30