How to match repository branchs at the bitbucket with Sonarcloud branchs?

sonarcloud
branches
bitbucket
(Mehmet Sergen Ergen) #1

Hello,
I didn’t see content about this topic at sonarsource community.
I want to match my branchs at repository branch with Sonarcloud branch.
But I wasn’t be successful.
If I work anohther branches (outside of master), I can’t see all code file.
I tried at Bitbucket pipelines and local.
And unfortunatelly there is a problem. I think these two problems are related.
I am adding bugs and duplications in my code because I want to test sonar-scanner at different situations. Sonar didn’t get completely and correct result outside of master.
I hope this is my fault. Because I worked on code analysis a lot of time.
I attached bitbucket-pipelines.yml, sonar-project.properties file and log file.

Properties file;

sonar.organization = ******

sonar.projectKey = *************

sonar.host.url = https://sonarcloud.io

sonar.login = ****************************

sonar.projectName = code-analysis 

sonar.sources=src

sonar.tests=test

sonar.branch.name=sonar_local_test

sonar.projectVersion = 1.1.5

sonar.cfamily.build-wrapper-output = bw-output 

sonar.cxx.cppcheck.reportPath=build/cppcheck-report.xml

sonar.language= c

sonar.sourceEncoding=UTF-8

sonar.cFamily.gcov.reportsPath=.

sonar.branch.name = sonar_local_test

sonar.branch.target = master

Log File;

INFO: Scanner configuration file: /home/msergenergen/Masaüstü/Dosyalar/sonar-scanner-3.3.0.1492-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/msergenergen/Masaüstü/Repo/code-analysis/sonar-project.properties
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Linux 4.15.0-46-generic amd64
INFO: User cache: /home/msergenergen/.sonar/cache
INFO: SonarQube server 7.7.0
INFO: Default locale: "tr_TR", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=443ms
INFO: Server id: BD367519-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /home/msergenergen/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=187ms
INFO: Load/download plugins (done) | time=19638ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: ********_code-analysis
INFO: Base dir: /home/msergenergen/Masaüstü/Repo/code-analysis
INFO: Working dir: /home/msergenergen/Masaüstü/Repo/code-analysis/.scannerwork
INFO: Load project settings for component key: '**********_code-analysis'
INFO: Load project settings for component key: '**********_code-analysis' (done) | time=84ms
INFO: Load project branches
INFO: Load project branches (done) | time=83ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=67ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=20ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=125ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=107ms
INFO: Load active rules
INFO: Load active rules (done) | time=2103ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=74ms
INFO: Organization key: **********
INFO: Branch name: sonar_local_test, type: short living
INFO: SCM collecting changed files in the branch
INFO: SCM collecting changed files in the branch (done) | time=155ms
INFO: Language is forced to c
INFO: Indexing files...
INFO: Project configuration:
INFO: 12 files indexed
INFO: Quality profile for c: Sonar way - ******** extension
INFO: ------------- Run sensors on module code-analysis
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=1ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=61ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms
INFO: Sensor CFamily [cpp]
INFO: Using build-wrapper output: /home/msergenergen/Masaüstü/Repo/code-analysis/bw-output/build-wrapper-dump.json
INFO: Available processors: 8
INFO: Using 1 thread for analysis according to value of "sonar.cfamily.threads" property.
WARN: Metric 'comment_lines_data' is deprecated. Provided value is ignored.
INFO: 0 compilation units analyzed
INFO: Sensor CFamily [cpp] (done) | time=1431ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=8ms
INFO: Sensor JavaSecuritySensor [security]
INFO: Reading UCFGs from: /home/msergenergen/Masaüstü/Repo/code-analysis/.scannerwork/ucfg2/java
INFO: 11:17:09.994 Building Type propagation graph
INFO: 11:17:09.997 Running Tarjan on 0 nodes
INFO: 11:17:09.998 Tarjan found 0 components
INFO: 11:17:09.998 Variable type analysis: done
INFO: UCFGs: 0, excluded: 0, source entrypoints: 0
INFO: No UCFGs have been included for analysis.
INFO: Sensor JavaSecuritySensor [security] (done) | time=53ms
INFO: Sensor CSharpSecuritySensor [security]
INFO: Reading UCFGs from: /home/msergenergen/Masaüstü/Repo/code-analysis/ucfg_cs2
INFO: 11:17:10 Building Type propagation graph
INFO: 11:17:10 Running Tarjan on 0 nodes
INFO: 11:17:10 Tarjan found 0 components
INFO: 11:17:10 Variable type analysis: done
INFO: UCFGs: 0, excluded: 0, source entrypoints: 0
INFO: No UCFGs have been included for analysis.
INFO: Sensor CSharpSecuritySensor [security] (done) | time=1ms
INFO: ------------- Run sensors on project
INFO: SCM provider for this project is: git
INFO: 4 files to be analyzed
INFO: 4/4 files analyzed
INFO: Calculating CPD for 6 files
INFO: CPD calculation finished
INFO: SCM writing changed lines
INFO: SCM writing changed lines (done) | time=55ms
INFO: Analysis report generated in 154ms, dir size=174 KB
INFO: Analysis report compressed in 17ms, zip size=45 KB
INFO: Analysis report uploaded in 365ms
INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=****************&branch=sonar_local_test&resolved=false
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AWk4VB8djzkievm53cm_
INFO: Analysis total time: 12.999 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 43.458s
INFO: Final Memory: 30M/346M
INFO: ------------------------------------------------------------------------

Bitbucket-pipelines.yml file;

image: atlassian/default-image:2
clone:
  depth: full
pipelines:
  default:
    - step:
        # sonar-scanner ve build-wrapper indirme işlemlerinin yapılacağı adım 
        script:
          - pwd
          - mkdir /opt/sonar
          - wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip
          - unzip sonar-scanner-cli-3.3.0.1492-linux.zip -d /opt/sonar/
          - wget -q https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
          - unzip build-wrapper-linux-x86.zip -d /home/build-wrapper/
          # chmod +x ile izin işlemleri için gerekli configler yapılacak
          - chmod +x /opt/sonar/sonar-scanner-3.3.0.1492-linux/bin/sonar-scanner
          - chmod +x /home/build-wrapper/build-wrapper-linux-x86/build-wrapper-linux-x86-64
          - export OS=linux
          - make clean -f makefile
          - make -f makefile
          - export PATH=$PATH:/opt/sonar/sonar-scanner-3.3.0.1492-linux/bin
          - export PATH=$PATH:/home/build-wrapper/build-wrapper-linux-x86
          - echo $PATH
          - cd /opt/atlassian/pipelines/agent/build
          - ls -al
          # build wrapper dosyasının çalıştırılması gerekmektedir
          - build-wrapper-linux-x86-64 --out-dir bw-output make clean all
          - /opt/sonar/sonar-scanner-3.3.0.1492-linux/bin/./sonar-scanner

How can I do?

Thanks.

I didn't see all file in Sonar Cloud while I'm doing code analysis in another branch(not master)
(Michal Duda) #3

I’m not entirely sure what’s wrong but one thing which looks very suspicious are the first two lines of the sonar scanner log:

INFO: Scanner configuration file: /home/msergenergen/Masaüstü/Dosyalar/sonar-scanner-3.3.0.1492-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/msergenergen/Masaüstü/Repo/code-analysis/sonar-project.properties

They point to your local filesystem and not Bitbucket Pipelines paths where you install the sonar-scanner-cli (/opt/sonar) and where Pipelines pull the repository (by default /opt/atlassian/pipelines/agent/build).

(Mehmet Sergen Ergen) #4

What is suspicious?
Can you explain in detail?

(Michal Duda) #5

Hi,
The logs you attached are from scanner that was not run in Bitbucket Cloud using Bitbucket Pipelines. It looks like you run it on local environment (judging by the paths in the logs). Please post the logs from a scanner that was executed on Bitbucket Cloud.

(Mehmet Sergen Ergen) #6

You misunderstood me.
This is my fault. I should have said it.
This is different log file which belong local environment.
I attached log file.
This belong Bitbucket Cloud.
Log file ;

`+ /opt/sonar/sonar-scanner-3.3.0.1492-linux/bin/./sonar-scanner`

`INFO: Scanner configuration file: /opt/sonar/sonar-scanner-3.3.0.1492-linux/conf/sonar-scanner.properties`

`INFO: Project root configuration file: /opt/atlassian/pipelines/agent/build/sonar-project.properties`

`INFO: SonarQube Scanner 3.3.0.1492`

`INFO: Java 1.8.0_121 Oracle Corporation (64-bit)`

`INFO: Linux 4.19.23-coreos-r1 amd64`

`INFO: Bitbucket Cloud Pipelines detected`

`INFO: User cache: /root/.sonar/cache`

`INFO: SonarQube server 7.7.0`

`INFO: Default locale: "en", source code encoding: "UTF-8"`

`INFO: Load global settings`

`INFO: Load global settings (done) | time=565ms`

`INFO: Server id: BD367519-AWHW8ct9-T_TB3XqouNu`

`INFO: User cache: /root/.sonar/cache`

`INFO: Load/download plugins`

`INFO: Load plugins index`

`INFO: Load plugins index (done) | time=119ms`

`INFO: Load/download plugins (done) | time=30932ms`

`INFO: Loaded core extensions: developer-scanner`

`INFO: Detected project key '****** from 'Bitbucket Cloud Pipelines'`

`INFO: Detected organization key '******' from 'Bitbucket Cloud Pipelines'`

`INFO: Process project properties`

`INFO: Execute project builders`

`INFO: Execute project builders (done) | time=4ms`

`INFO: Project key: *****************************`

`INFO: Base dir: /opt/atlassian/pipelines/agent/build`

`INFO: Working dir: /opt/atlassian/pipelines/agent/build/.scannerwork`

`INFO: Load project settings for component key: '*****************************`

`INFO: Load project settings for component key: '*****************************' (done) | time=115ms`

`INFO: Load project branches`

`INFO: Load project branches (done) | time=100ms`

`INFO: Load project pull requests`

`INFO: Load project pull requests (done) | time=96ms`

`INFO: Load branch configuration`

`INFO: Load branch configuration (done) | time=3ms`

`INFO: Load project repositories`

`INFO: Load project repositories (done) | time=128ms`

`INFO: Load quality profiles`

`INFO: Load quality profiles (done) | time=122ms`

`INFO: Load active rules`

`INFO: Load active rules (done) | time=2923ms`

`INFO: Organization key: *****************************`

`INFO: Branch name: master, type: long living`

`INFO: Language is forced to c`

`INFO: Indexing files...`

`INFO: Project configuration:`

`INFO: 12 files indexed`

`INFO: Quality profile for c: Sonar way - ***************************** extension`

`INFO: ------------- Run sensors on module code-analysis`

`INFO: Load metrics repository`

`INFO: Load metrics repository (done) | time=102ms`

`INFO: Sensor JavaXmlSensor [java]`

`INFO: Sensor JavaXmlSensor [java] (done) | time=2ms`

`INFO: Sensor HTML [web]`

`INFO: Sensor HTML [web] (done) | time=42ms`

`INFO: Sensor JaCoCo XML Report Importer [jacoco]`

`INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=6ms`

`INFO: Sensor CFamily [cpp]`

`INFO: Using build-wrapper output: /opt/atlassian/pipelines/agent/build/bw-output/build-wrapper-dump.json`

`INFO: Available processors: 8`

`INFO: Using 1 thread for analysis according to value of "sonar.cfamily.threads" property.`

`WARN: Metric 'comment_lines_data' is deprecated. Provided value is ignored.`

`INFO: [pool-1-thread-1] /opt/atlassian/pipelines/agent/build/src/CircularBuffer.c`

`INFO: [pool-1-thread-1] /opt/atlassian/pipelines/agent/build/src/dcop_steci.c`

`INFO: [pool-1-thread-1] /opt/atlassian/pipelines/agent/build/src/dcop_mw_datachannel.c`

`INFO: [pool-1-thread-1] /opt/atlassian/pipelines/agent/build/src/package_control.c`

`INFO: [pool-1-thread-1] /opt/atlassian/pipelines/agent/build/src/dcop_flasher.c`

`INFO: [pool-1-thread-1] /opt/atlassian/pipelines/agent/build/src/dcop_crc_calc.c`

`INFO: 6 compilation units analyzed`

`INFO: Sensor CFamily [cpp] (done) | time=4786ms`

`INFO: Sensor JavaSecuritySensor [security]`

`INFO: Reading UCFGs from: /opt/atlassian/pipelines/agent/build/.scannerwork/ucfg2/java`

`INFO: 08:14:58.94 Building Type propagation graph`

`INFO: 08:14:58.943 Running Tarjan on 0 nodes`

`INFO: 08:14:58.943 Tarjan found 0 components`

`INFO: 08:14:58.943 Variable type analysis: done`

`INFO: UCFGs: 0, excluded: 0, source entrypoints: 0`

`INFO: No UCFGs have been included for analysis.`

`INFO: Sensor JavaSecuritySensor [security] (done) | time=8ms`

`INFO: Sensor CSharpSecuritySensor [security]`

`INFO: Reading UCFGs from: /opt/atlassian/pipelines/agent/build/ucfg_cs2`

`INFO: 08:14:58.945 Building Type propagation graph`

`INFO: 08:14:58.945 Running Tarjan on 0 nodes`

`INFO: 08:14:58.945 Tarjan found 0 components`

`INFO: 08:14:58.945 Variable type analysis: done`

`INFO: UCFGs: 0, excluded: 0, source entrypoints: 0`

`INFO: No UCFGs have been included for analysis.`

`INFO: Sensor CSharpSecuritySensor [security] (done) | time=0ms`

`INFO: ------------- Run sensors on project`

`INFO: Sensor Zero Coverage Sensor`

`INFO: Sensor Zero Coverage Sensor (done) | time=13ms`

`INFO: Calculating CPD for 6 files`

`INFO: CPD calculation finished`

`INFO: Analysis report generated in 110ms, dir size=298 KB`

`INFO: Analysis report compressed in 28ms, zip size=83 KB`

`INFO: Analysis report uploaded in 543ms`

`INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=*****************************&branch=master`

`INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report`

`INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AWmkd6oyk8L8EpDFUyvP`

`INFO: Analysis total time: 12.973 s`

`INFO: ------------------------------------------------------------------------`

`INFO: EXECUTION SUCCESS`

`INFO: ------------------------------------------------------------------------`

`INFO: Total time: 48.173s`

`INFO: Final Memory: 34M/618M`

`INFO: ------------------------------------------------------------------------`