title: Gitlab coverage badge always unknow
body: <h2>The problem</h2>
  <p>I'm working on a Laravel package project and setting up a pipeline to test it (against php 7.3, 7.4 and 8.0) on merge request and publishing it to my package registry on main branch.</p>
  <p>I'm trying to set up a badge for code coverage, but i can't make it work correctly since it is always dipslayng <code>unknown</code> percentage.</p>
  <h2>What i've done</h2>
  <h3>The pipeline</h3>
  <pre class="lang-yaml prettyprint-override"><code>stages:
    - dependancies
    - linting
    - test
    - publish
  
  # Dependancies job
  download dependancies:
    stage: dependancies
    # job stuff
  
  # Linting jobs
  phpcs:
    stage: linting
    # job stuff
  
  # test jobs templates
  .testing_template: &amp;testing
    stage: test
    script:
      - php -dxdebug.mode=coverage vendor/bin/phpunit --coverage-text --colors=never
    only:
      - merge_requests
  
  # Testing jobs
  php 8:
    image: mileschou/xdebug:8.0
    &lt;&lt;: *testing
  
  php 7.4:
    image: mileschou/xdebug:7.4
    &lt;&lt;: *testing
  
  php 7.3:
    image: mileschou/xdebug:7.3
    &lt;&lt;: *testing
  
  
  #  Publish to package registry
  publish:
    only:
      - master
      - tags
    # job stuff
  </code></pre>
  <p>So my pipeline works as follow:</p>
  <ul>
  <li>on the feature branch
  <ul>
  <li>download dependancies</li>
  <li>lint code</li>
  <li>test against php 7.3, 7.4 and 8.0</li>
  </ul>
  </li>
  <li>on the main branch and on tags
  <ul>
  <li>publish the package to the packages registry</li>
  </ul>
  </li>
  </ul>
  <p>So the part executed on the merge request is as follow</p>
  <p><a href="https://i.stack.imgur.com/z0tKE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/z0tKE.png" alt="enter image description here" /></a></p>
  <p>Moreover, i can see code coverage for each test job in the pipeline job section</p>
  <p><a href="https://i.stack.imgur.com/kFiv7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kFiv7.png" alt="enter image description here" /></a></p>
  <p>(I'm not sure why the tests results in different code coverage percentages since the codebase is the same, but is obviously related to the php version and probably specific optimizations done in code parsing.)</p>
  <h3>The badge</h3>
  <p>Since this is a Laravel package project i'm testing it with PhpUnit, so i used the given regex for the test coverage parsing setting (taken from the Gitlab <a href="https://docs.gitlab.com/ee/ci/pipelines/settings.html#test-coverage-parsing" rel="noreferrer">docs</a>).</p>
  <pre class="lang-regex prettyprint-override"><code>^\s*Lines:\s*\d+.\d+\%
  </code></pre>
  <p>I want a badge that show the code coverage status on the <code>master branch</code>, not on the feature branch, so i've created a coverage badge with the badge image url as follow (i added a reference to a specific test job, i.e. <code>php 7.4</code>)</p>
  <pre><code>https://gitlab.com/%{project_path}/badges/%{default_branch}/coverage.svg?job=php%207.4
  </code></pre>
  <p>but it keeps being displayed as</p>
  <p><a href="https://i.stack.imgur.com/ogMzY.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ogMzY.png" alt="enter image description here" /></a>.</p>
  <p>I've tought that Gitlab can't find the desired <code>php 7.4</code> job since it is not executed on the <code>master</code> branch but on a feature branch, so i tried replacing the <code>%{default_branch}</code> placeholder with the <code>%{commit_sha}</code> to reference a specific commit, but this doesn't work neither since (i suppose) it reference the merge commit (that triggered just the publish job) and not the one that triggered the entire pipeline.</p>
  <h2>I'm stuck</h2>
  <p>I cannot figure out how to get the code coverage percentage for the <code>master</code> branch.</p>
  <p>I don't want to execute testing again on the master branche since i've already tested the feature branch before merging it.</p>
  <p>How can i do? Am I missing something?</p>