简体   繁体   中英

Gitlab's coverage badge showing always unknown

I'm trying to setup the coverage badge in my project written in PHP, but it always remain as unknown . My current settings are:

1. .gitlab-ci.yml test job:

php_unit:
    stage: Test
    image: $PHP_FPM_ALPINE_IMAGE
    tags:
        - docker
    except:
        - tags
    when: on_success
    <<: *backend_cache_config
    <<: *backend_before_script
    script:
        - phpdbg -qrr vendor/bin/phpunit --coverage-text --colors=never 
    coverage: '/^\s*Lines:\s*\d+.\d+\%/'

2. Test coverage regex set in Settings > CI/CD > General Pipelines:

在此处输入图像描述

3. Badge configuration in Settings > General > Badges

在此处输入图像描述


Even with this settings, the badge stay as unknown . I've tried some of the things below, but with no success:

Any ideas?

Gitlab CIs Test coverage report badge shows unknown when no coverage information was obtained.

This is certainly the error condition, eg you expect to have at least some different match here (good / acceptable / medium / low).

For it to work, the job log must contain at least one line (the last would be taken) that matches the regular expression form the job keywords coverage key word.

You coverage regular expression is:

/^\s*Lines:\s*\d+.\d+\%/

This regular expression has to match the coverage percentage number (incl. zero) and the match may contain surrounding text.

The actual number for the badge is matched by \d+(\.\d+)? on your regular expression match.

The most detailed description about how this regular expression works can be obtained from the coverage key word documentation .

As you have not shared any job log that you expect your regular expression to match against not much specifically can be said.

It appears as a configuration issue to me, and it is either that the expectation is wrong that it would match against the job log output while it does not (you can easily validate this with a regular expression test tool either on your box or online at https://regex101.com/ ) - or - there is a match but the matched number can not be parsed by Gitlab CI (which from my own feeling is less likely).

If you have a match of a line of your job log, then verify that match as the subject against the match of another regular expression, \d+(\.\d+)? , as that is the one Gitlab uses to obtain the actual number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM