title: Sonarcloud shows 0% coverage on new code, and also shows 0% coverage on master branch with gitlab ci
body: <p>I am using GitLab ci to run SonarCloud code analysis on the code.</p>
  <p>here is my gitlab-ci.yaml</p>
  <pre class="lang-yaml prettyprint-override"><code>stages:
    - test
  
  before_script:
    - mkdir -p ~/.ssh &amp;&amp;
      cp $gitlab_private_key ~/.ssh/id_ed25519 &amp;&amp;
      chmod 600 ~/.ssh/id_ed25519 &amp;&amp;
      touch ~/.ssh/known_hosts &amp;&amp;
      ssh-keyscan gitlab.com &gt;&gt; ~/.ssh/``known_hosts
  
  variables:
    SONAR_USER_HOME: &quot;${CI_PROJECT_DIR}/.sonar&quot;  # Defines the location of the analysis task cache
    GIT_DEPTH: &quot;0&quot;  # Tells git to fetch all the branches of the project, required by the analysis task
    GITLAB_PROJECT_ID: ${CI_PROJECT_ID} # needed to be exported to the project's environments
    FLASK_APP: manage.py
  
  sonarcloud-check:
    image:
      name: sonarsource/sonar-scanner-cli:latest
      entrypoint: [&quot;&quot;]
    cache:
      key: &quot;${CI_JOB_NAME}&quot;
      paths:
        - .sonar/cache
    script:
      - sonar-scanner
    only:
      - merge_requests
      - master
  
  test-merge-request-changes:
    stage: test
    only:
      - merge_requests
    image:
      name: docker:19.03.13-git
    services:
      - name: docker:19.03.0-dind
        entrypoint: [&quot;env&quot;, &quot;-u&quot;, &quot;DOCKER_HOST&quot;]
        command: [&quot;dockerd-entrypoint.sh&quot;]
    variables:
      DOCKER_HOST: tcp://localhost:2375
      DOCKER_TLS_CERTDIR: &quot;&quot;
      DOCKER_DRIVER: overlay2
      ENV: test
      CI_DEBUG_TRACE: &quot;true&quot;
    before_script:
      - echo $CI_BUILD_TOKEN | docker login -u gitlab-ci-token --password-stdin ${CI_REGISTRY}
    script:
      - echo &quot;Running Tests...&quot;
      - cp ${group_shared_vars} ${CI_PROJECT_DIR}/.env
      - docker build . -f Dockerfile-testing -t test_merge_req --build-arg GITLAB_PROJECT_ID=${GITLAB_PROJECT_ID}
      - docker run --cidfile=&quot;my-package.txt&quot; test_merge_req:latest
  
    after_script:
      - touch text2.txt
      - docker cp $(cat my-package.txt):/app/tests/coverage/coverage.xml coverage.xml
      - docker cp $(cat my-package.txt):/app/tests/coverage/junit.xml junit.xml
    timeout: 2h
    artifacts:
      when: always
      reports:
        cobertura:
          - coverage.xml
        junit:
          - junit.xml
    coverage: '/TOTAL.*\s+(\d+%)$/'
  
  </code></pre>
  <p>And here is my <code>sonar-project.properties</code></p>
  <pre><code>sonar.projectKey=my_app-key
  sonar.organization=my_org
  
  sonar.sources=lib
  sonar.tests=tests
  sonar.exclusions=tests
  sonar.language=python
  sonar.python.version=3.8
  
  </code></pre>
  <p>I want to get the report that is generated in the container analyzed by sonarcloud on each merge request.</p>
  <p>Also, when a code is pushed to the master branch, I want to get the coverage percent on sonarcloud of the project to be updated but it just shows 0%.</p>
  <p>Is there any way that after the merge requests are run, we get the sonarcloud analysis on the report of the docker container?</p>
  <p>And also getting the master branch coverage updated without having to commit the <code>coverage.xml</code> to the repo?</p>