Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Sonarscan and bitbucket, bad paths

Hello

I'm trying to configure CI on my project. Here, is the bitbucket-pipelines.yml:

clone:
    depth: full

pipelines:
    branches:
        '{master}':
            - step:
                  name: Tests PHPUnit
                  services:
                      - docker
                  caches:
                      - docker
                  script:
                      - curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
                      - chmod +x /usr/local/bin/docker-compose
                      - cd scripts
                      - sh smf_recreate.sh
                      - sh smf_init.sh
                      - sh smf_tests.sh
                  artifacts:
                      - back/test-reports/**
                      - back/src/**
                      - back/tests/**
            - step:
                  name: Analyse SonarQube
                  image: maven:3.8.1
                  caches:
                      - sonar
                  script:
                      - mkdir -p /usr/src/app/
                      - mv back/src/ /usr/src/app/
                      - mv back/tests/ /usr/src/app/
                      - pipe: sonarsource/sonarqube-scan:1.0.0
                        variables:
                            SONAR_HOST_URL: ${SONAR_HOST_URL}
                            SONAR_TOKEN: ${SONAR_TOKEN}

definitions:
    caches:
        sonar: ~/.sonar

The first step creates a docker container, wich make PHPUnit test, and export the test-reports (artifacts) to the next step.

The result-coverage.yml look like this :

<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1629298870">
  <project timestamp="1629298870">
    <file name="/usr/src/app/src/Controller/TempController.php">
      <class name="App\Controller\TempController" namespace="global">
        <metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
      </class>
      <metrics loc="15" ncloc="10" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
    </file>
    <file name="/usr/src/app/src/EventListener/Listener.php">
      <class name="App\EventListener\Listener" namespace="global">
        <metrics complexity="9" methods="6" coveredmethods="6" conditionals="0" coveredconditionals="0" statements="23" coveredstatements="23" elements="29" coveredelements="29"/>
      </class>
      <line num="32" type="method" name="__construct" visibility="public" complexity="1" crap="1" count="4"/>
      <line num="34" type="stmt" count="4"/>
      <line num="35" type="stmt" count="4"/>
      <line num="43" type="method" name="prePersist" visibility="public" complexity="1" crap="1" count="1"/>
      <line num="46" type="stmt" count="1"/>
      <line num="47" type="stmt" count="1"/>
      <line num="48" type="stmt" count="1"/>
      <line num="56" type="method" name="postPersist" visibility="public" complexity="1" crap="1" count="1"/>
      <line num="58" type="stmt" count="1"/>
      <line num="66" type="method" name="preUpdate" visibility="public" complexity="1" crap="1" count="1"/>
      <line num="68" type="stmt" count="1"/>
      <line num="69" type="stmt" count="1"/>
      <line num="76" type="method" name="postUpdate" visibility="public" complexity="1" crap="1" count="1"/>
      <line num="78" type="stmt" count="1"/>
      <line num="79" type="stmt" count="1"/>
      <line num="80" type="stmt" count="1"/>
      <line num="82" type="stmt" count="1"/>
      <line num="91" type="method" name="history" visibility="private" complexity="4" crap="4" count="2"/>
      <line num="93" type="stmt" count="2"/>
      <line num="94" type="stmt" count="2"/>
      <line num="95" type="stmt" count="2"/>
      <line num="97" type="stmt" count="2"/>
      <line num="100" type="stmt" count="2"/>
      <line num="101" type="stmt" count="2"/>
      <line num="102" type="stmt" count="2"/>
      <line num="103" type="stmt" count="2"/>
      <line num="104" type="stmt" count="2"/>
      <line num="106" type="stmt" count="2"/>
      <line num="108" type="stmt" count="2"/>
      <metrics loc="110" ncloc="69" classes="1" methods="6" coveredmethods="6" conditionals="0" coveredconditionals="0" statements="23" coveredstatements="23" elements="29" coveredelements="29"/>
    </file>
    <file name="/usr/src/app/src/EventListener/ExceptionListener.php">
      <class name="App\EventListener\ExceptionListener" namespace="global">
        <metrics complexity="3" methods="2" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="20" coveredstatements="20" elements="22" coveredelements="22"/>
      </class>
      <line num="27" type="method" name="__construct" visibility="public" complexity="1" crap="1" count="1"/>
      <line num="29" type="stmt" count="1"/>
      <line num="30" type="stmt" count="1"/>
      <line num="36" type="method" name="onKernelException" visibility="public" complexity="2" crap="2" count="1"/>
      <line num="38" type="stmt" count="1"/>
      <line num="40" type="stmt" count="1"/>
      <line num="42" type="stmt" count="1"/>
      <line num="46" type="stmt" count="1"/>
      <line num="47" type="stmt" count="1"/>
      <line num="48" type="stmt" count="1"/>
      <line num="49" type="stmt" count="1"/>
      <line num="50" type="stmt" count="1"/>
      <line num="51" type="stmt" count="1"/>
      <line num="52" type="stmt" count="1"/>
      <line num="53" type="stmt" count="1"/>
      <line num="55" type="stmt" count="1"/>
      <line num="56" type="stmt" count="1"/>
      <line num="58" type="stmt" count="1"/>
      <line num="59" type="stmt" count="1"/>
      <line num="60" type="stmt" count="1"/>
      <line num="62" type="stmt" count="1"/>
      <line num="63" type="stmt" count="1"/>
      <metrics loc="65" ncloc="50" classes="1" methods="2" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="20" coveredstatements="20" elements="22" coveredelements="22"/>
    </file>
    <metrics files="3" loc="190" ncloc="129" classes="2" methods="8" coveredmethods="8" conditionals="0" coveredconditionals="0" statements="43" coveredstatements="43" elements="51" coveredelements="51"/>
  </project>
</coverage>

As we can see, the "file" attributes starts by "/usr/src/app" wich is the context of my docker container.

The problem is on the 2nd step, when Sonarscan trying to analyse the files, he can't find them because it is trying to check at /usr/src/app...

INFO: Analyzing PHPUnit coverage report: back/test-reports/result-coverage.xml

WARN: Could not resolve 3 file paths in result-coverage.xml, first unresolved path: /usr/src/app/src/Controller/TempController.php

Indeed, in the sonarscan container (2nd step), they are located at /back/src/** ... How can I tell sonarscan to look at this directory, and not the one specified in result-coverage.xml ?

Thanks !

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

229 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you