【问题标题】:SonarQube with Travis not showing issues on dot net core 2 project带有 Travis 的 SonarQube 未显示 dot net core 2 项目的问题
【发布时间】:2019-04-29 05:19:55
【问题描述】:

我有一个简单的 dotnet core 2.0 项目,它有一个简单的问题,它使 SonarLint 因未使用的变量问题而失败。

代码存储在公共 github 存储库 (here) 中。 travis 作业 (here) 运行并具有 SonarQube 插件,应该发布到 SonarCloud (here)。

我遇到的问题是分析没有发现这个问题并作为问题发布。我显然有一些设置不正确,但我不知道是什么。

我的 .travis.yml 在下面

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

我的 sonar-project.properties 文件在下面

# 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

在我的 travis 日志中:

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

这是影响分析的因素吗?如果是这样,我该如何解决?如果不是还有什么在停止文件分析,请问?

编辑: 我可以在日志中看到以下内容,但它仍然没有被 SoanrQube 拾取..

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

编辑 2: 我设法让分析的数字上升,见下文......

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

...在我的 .travis.yml 中使用以下内容

install:
  - git fetch --unshallow --tags

来自这里: https://stackoverflow.com/a/47441734/254215

【问题讨论】:

    标签: .net-core sonarqube travis-ci


    【解决方案1】:

    好的,我还没有摆脱困境,但我正在使用以下 .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
    

    【讨论】:

      【解决方案2】:

      最后我使用的 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.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
      

      构建文件是这样的。

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

      测试是这样的。

      # 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
      

      我没有使用sonar-project.properties 文件。

      HTH 某人,有一天

      【讨论】:

        猜你喜欢
        • 2017-07-11
        • 1970-01-01
        • 1970-01-01
        • 2017-09-03
        • 1970-01-01
        • 1970-01-01
        • 2021-07-19
        • 1970-01-01
        • 2017-06-07
        相关资源
        最近更新 更多