Code coverage bage not from latest pipeline in Gitlab-CI

Viewed 168

I've got badge like

![coverage](https://gitlab.com/gitlab-org/gitlab/badges/main/coverage.svg?job=test:coverage)

As you can see, I've got job named "test:coverage", which has coverage report.

Problem is, this job doesn't appear in every pipeline. This job only runs once a day in scheduled pipeline. When this scheduled pipeline IS the latest pipeline, badge works just fine. But when it can't find this "test:coverage" job in the latest pipeline, it shows "unknown".

Is there some way to force Gitlab to look for job not only in latest pipeline?

1 Answers

Okay, so I couldn't find any solution, so here's workaround.

  1. On test:coverage task, add line, which saves code coverage line from test log to separate file (which has to be accessable for any build) like this: cat $CI_PROJECT_DIR/app/protected/runtime/codecept.txt | grep 'Lines:.*[0-9]%' > /tmp/coveragePercentage.txt

  2. Then, in no-coverage task, print this file to log: cat /tmp/coveragePercentage.txt

  3. Remove ?job=... part from badge url

That solves the problem.

Related