4

我已经在这个问题上苦苦挣扎了几天,我似乎无法确定我做错了什么。

我一直在尝试分析用travis CI构建并在sonarcloud中分析的 ac# 项目。

我已经设置了 travis(参见:https ://travis-ci.org/ShiveringSquirrel/heroes-app-webapi )来构建,它似乎工作正常。

配置

.travis.yml

language: csharp
solution: heroes-app-webapi.sln
dist: trusty
sudo: required

mono:
  - latest

install:
  - nuget restore heroes-app-webapi.sln
  - nuget install NUnit.Console -Version 3.9.0 -OutputDirectory testrunner

addons:
  sonarcloud:
    organization: "shiveringsquirrel-github"
    token:
      secure: $SONAR_TOKEN

script:
  - msbuild /p:Configuration=Release /target:rebuild heroes-app-webapi.sln
  - mono ./testrunner/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe ./heroes-app-webapi.Tests/bin/Release/heroes-app-webapi.Tests.dll
  - sonar-scanner -Dsonar.projectVersion=1.$TRAVIS_BUILD_NUMBER

cache:
  directories:
    - '$HOME/.sonar/cache'

git:
  clone: true
  quiet: false
  depth: false
  submodules: true

# blocklist
branches:
  except:
  - legacy
  - experimental

# safelist
branches:
  only:
  - master
  - stable

请参阅声纳项目.properties

sonar.projectKey=ShiveringSquirrel_heroes-app-webapi
sonar.projectName=heroes-app-webapi
#sonar.projectVersion=1.0
sonar.projectDescription=The backend API for the Heroes test application

sonar.links.homepage=https://github.com/ShiveringSquirrel/heroes-app-webapi
sonar.links.ci=https://travis-ci.org/ShiveringSquirrel/heroes-app-webapi
sonar.links.scm=https://github.com/ShiveringSquirrel/heroes-app-webapi
sonar.links.issue=https://github.com/ShiveringSquirrel/heroes-app-webapi/issues

#sonar.sources=.
#sonar.sources=src/main
#sonar.tests=src/test
sonar.sources=heroes-app-webapi
sonar.tests=heroes-app-webapi.Tests

sonar.scm.provider=git
sonar.scm.forceReloadAll=true

sonar.dotnet.visualstudio.testProjectPattern=*.Test
sonar.language=cs
sonar.sourceEncoding=UTF-8
sonar.verbose=true
sonar.exclusions=**/*.xml
sonar.inclusions=**/*.cs

sonar.cs.nunit.reportsPaths=TestResult.xml

建造

travis 的完整构建日志:查看完整构建日志

一些相关的片段形成了日志:

$ mono --version
Mono JIT compiler version 5.20.1.19 (tarball Thu Apr 11 09:05:42 UTC 2019)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    Interpreter:   yes
    LLVM:          yes(600)
    Suspend:       hybrid
    GC:            sgen (concurrent by default)
$ msbuild /version
Microsoft (R) Build Engine version 16.0.0.0 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

使用 msbuild 构建

$ msbuild /p:Configuration=Release /target:rebuild heroes-app-webapi.sln
....
    302 Warning(s)
    0 Error(s)
Time Elapsed 00:00:06.94
The command "msbuild /p:Configuration=Release /target:rebuild heroes-app-webapi.sln" exited with 0.

单元测试

$ mono ./testrunner/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe ./heroes-app-webapi.Tests/bin/Release/heroes-app-webapi.Tests.dll
....
Test Run Summary
  Overall result: Passed
  Test Count: 25, Passed: 25, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2019-07-14 21:00:34Z
    End time: 2019-07-14 21:00:36Z
    Duration: 2.559 seconds
Results (nunit3) saved as TestResult.xml
The command "mono ./testrunner/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe ./heroes-app-webapi.Tests/bin/Release/heroes-app-webapi.Tests.dll" exited with 0.

声纳扫描仪

$ sonar-scanner -Dsonar.projectVersion=1.$TRAVIS_BUILD_NUMBER
...
21:00:40.716 DEBUG: Plugins:
...
21:00:40.717 DEBUG:   * SonarC# 7.15.0.8572 (csharp)
...
21:00:46.518 DEBUG: 77 non excluded files in this Git repository
21:00:46.541 DEBUG: 'heroes-app-webapi/Global.asax.cs' indexed with language 'cs'
21:00:46.549 DEBUG: 'heroes-app-webapi/Attributes/JwtAuthenticationAttribute.cs' indexed with language 'cs'
...
21:00:46.802 INFO: 30 files indexed
21:00:46.803 INFO: 0 files ignored because of inclusion/exclusion patterns
21:00:46.804 INFO: 0 files ignored because of scm ignore settings
21:00:46.805 INFO: Quality profile for cs: Sonar way
21:00:46.806 INFO: ------------- Run sensors on module heroes-app-webapi
...
21:00:51.019 INFO: Sensor C# Properties [csharp]
21:00:51.021 WARN: No Roslyn issues report found for this project.
...
21:00:51.052 INFO: Sensor C# Unit Test Results Import [csharp]
21:00:51.054 INFO: Parsing the NUnit Test Results file /home/travis/build/ShiveringSquirrel/heroes-app-webapi/./TestResult.xml
...
21:00:51.713 INFO: SCM provider for this project is: git
21:00:51.715 INFO: 27 files to be analyzed
...
21:00:52.065 INFO: 27/27 files analyzed
21:00:52.068 INFO: Calculating CPD for 0 files
21:00:52.078 INFO: CPD calculation finished
21:00:52.235 INFO: Analysis report generated in 151ms, dir size=190 KB
21:00:52.288 INFO: Analysis report compressed in 51ms, zip size=56 KB
21:00:52.289 INFO: Analysis report generated in /home/travis/build/ShiveringSquirrel/heroes-app-webapi/.scannerwork/scanner-report
21:00:52.290 DEBUG: Upload report
21:00:52.630 DEBUG: POST 200 https://sonarcloud.io/api/ce/submit?organization=shiveringsquirrel-github&projectKey=ShiveringSquirrel_heroes-app-webapi&projectName=heroes-app-webapi | time=338ms
21:00:52.633 INFO: Analysis report uploaded in 343ms
21:00:52.637 INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarcloud.io/dashboard?id=ShiveringSquirrel_heroes-app-webapi
21:00:52.637 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
21:00:52.639 INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AWvySdH4BABcSdLoSktk
21:00:52.640 DEBUG: Report metadata written to /home/travis/build/ShiveringSquirrel/heroes-app-webapi/.scannerwork/report-task.txt
21:00:52.646 DEBUG: Post-jobs : 
21:00:52.650 INFO: Analysis total time: 11.885 s
21:00:52.652 INFO: ------------------------------------------------------------------------
21:00:52.656 INFO: EXECUTION SUCCESS
21:00:52.658 INFO: ------------------------------------------------------------------------
21:00:52.662 INFO: Total time: 15.232s
21:00:52.860 INFO: Final Memory: 34M/349M
21:00:52.860 INFO: ------------------------------------------------------------------------
21:00:52.860 DEBUG: Execution getVersion
21:00:52.860 DEBUG: Execution stop
The command "sonar-scanner -Dsonar.projectVersion=1.$TRAVIS_BUILD_NUMBER" exited with 0.

所以对我来说,这一切看起来都不错,只有在 sonarcloud.io ( https://sonarcloud.io/dashboard?id=ShiveringSquirrel_heroes-app-webapi ) 中我没有看到任何分析。

甚至没有几行代码,它确实更新了我的内部版本号和其他设置。但没有报告或分析。如果我查看后台任务:

21:00:52.639 INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AWvySdH4BABcSdLoSktk

它说“成功”。我试图调查的另一件事是我收到的一个警告:

21:00:51.021 WARN: No Roslyn issues report found for this project.

但在我看来,从日志中一切都得到了正确的分析......有什么想法吗?

4

0 回答 0