0

I have a simple dotnet core 2.0 project with a simple issue which is failing SonarLint with an unused variable issue.

enter image description here

The code is stored in a public github repository (here). A travis job (here) runs and has the SonarQube plugin and should post to SonarCloud (here).

The problem I have is that this issue is not being picked up by the analysis and published as an issue. I obviously have something set up incorrectly but I dont know what.

My .travis.yml is below

language: csharp
dist: xenial
sudo: required
mono: none
dotnet: 2.0.0
solution: Dibware.Salon.sln
addons:
  sonarcloud:
    organization: "dibley1973-github" # the key of the org you chose at step #3
    token:
      secure: $SONAR_TOKEN
branches:
  only:
    - master
before_script:
  - chmod +x build.sh
  - chmod +x run-tests.sh
script:
  - ./build.sh
  - ./run-tests.sh
  - sonar-scanner

My sonar-project.properties file is below

# Project identification
sonar.projectKey=Core:Dibware.Salon
sonar.projectVersion=1.0.0.0
sonar.projectName=Dibware.Salon

# Info required for SonarQube
sonar.sources=./Domain
sonar.language=cs
sonar.sourceEncoding=UTF-8

C# Settings
sonar.dotnet.visualstudio.solution=Dibware.Salon.sln

# MSBuild
sonar.dotnet.buildConfiguration=Release
sonar.dotnet.buildPlatform=Any CPU

# StyleCop 
sonar.stylecop.mode=

# SCM
sonar.scm.enabled=false

In the travis log I do have:

INFO: 27 files to be analyzed
WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with 'git fetch --unshallow'.
INFO: 0/27 files analyzed
WARN: Missing blame information for the following files:
WARN:   *
.
<lots of files>
.
WARN: This may lead to missing/broken features in SonarQube
INFO: Calculating CPD for 0 files
INFO: CPD calculation finished
INFO: Analysis report generated in 216ms, dir size=381 KB
INFO: Analysis report compressed in 56ms, zip size=89 KB
INFO: Analysis report uploaded in 340ms
INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=Core%3ADibware.Salon
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=AWo0YQeAUanQDuOXxh79
INFO: Analysis total time: 11.484 s

Is this what is affecting the analysis? If so how do I resolve it? If not what else is stopping the analysis of the files, please?

EDIT: I can see the following in the log, but it still does not get picked up by SoanrQube..

Chair.cs(17,17): warning CS0219: The variable 'a' is assigned but its value is never used 

Edit 2: I managed to getthe analzed number to go up, see below...

INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=6ms
INFO: SCM provider for this project is: git
INFO: 27 files to be analyzed
INFO: 27/27 files analyzed
INFO: Calculating CPD for 0 files

... using the following in my .travis.yml

install:
  - git fetch --unshallow --tags

That came from here: https://stackoverflow.com/a/47441734/254215

Dib
  • 2,001
  • 2
  • 29
  • 45

2 Answers2

0

Ok, I am not out of the wood yet, but am getting some analysis using the following .travis.yml

language: csharp
dist: xenial
sudo: required
mono: none
dotnet: 2.1.300

solution: Dibware.Salon.sln

addons:
  sonarcloud:
    organization: "dibley1973-github" # the key of the org you chose at step #3
    token:
      secure: $SONAR_TOKEN

branches:
  only:
    - master

install:
  - dotnet tool install --global dotnet-sonarscanner
  - git fetch --unshallow --tags

before_script:
  - export PATH="$PATH:$HOME/.dotnet/tools"
  - chmod +x build.sh
  - chmod +x run-tests.sh

script:
  - dotnet sonarscanner begin /k:"Core:Dibware.Salon" /d:sonar.login="$SONAR_TOKEN" /d:sonar.exclusions="**/bin/**/*,**/obj/**/*" /d:sonar.cs.opencover.reportsPaths="lcov.opencover.xml" || true
  - ./build.sh
  - ./run-tests.sh
  - dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN" || true
Dib
  • 2,001
  • 2
  • 29
  • 45
0

In the end the travis.yml file I used which worked is this:

language: csharp
dist: xenial
sudo: required
mono: none
dotnet: 2.1.300

solution: Dibware.Salon.sln

addons:
  sonarcloud:
    organization: "dibley1973-github" # the key of the org you chose at step #3
    token:
      secure: $SONAR_TOKEN

branches:
  only:
    - master

install:
  - dotnet tool install --global dotnet-sonarscanner
  - git fetch --unshallow --tags

before_script:
  - export PATH="$PATH:$HOME/.dotnet/tools"
  - chmod +x build.sh
  - chmod +x run-tests.sh

script:
  - dotnet sonarscanner begin /k:"Core:Dibware.Salon" /d:sonar.login="$SONAR_TOKEN" /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" /d:sonar.exclusions="**/bin/**/*,**/obj/**/*,**/Dibware.Salon.Web/**/*" || true
  - ./build.sh
  - ./run-tests.sh
  - dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN" || true

The build file is this.

#!/usr/bin/env bash
dotnet restore
dotnet clean -c Release
dotnet build Dibware.Salon.sln -c Release

The test is this.

# Run the tests and collate code coverage results
dotnet test -c Release --no-build --no-restore Domain/SharedKernel/Dibware.Salon.Domain.SharedKernel.UnitTests/Dibware.Salon.Domain.SharedKernel.UnitTests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover

I did not use a sonar-project.properties file.

HTH someone, one day

Dib
  • 2,001
  • 2
  • 29
  • 45