SonarQube 扫描仪失败,出现“不在 git 工作树内”错误
SonarQube Scanner fails with “Not inside a git worktree” error
我在 C#
项目中使用 Travis CI 到 运行 SonarQube 扫描仪。我设法让扫描器工作了一次,但在下一次提交时没有明显原因失败(提交已更新 README.md
)。
我尝试清除构建缓存,但没有成功。我也读过其他编程语言(Java 主要)的问题,但到目前为止运气不好。
错误日志
具体错误为:
Not inside a Git work tree: /home/travis/build/presque-fini
完整的错误日志如下:
34.72s$ mono ./scanner/SonarScanner.MSBuild.exe end -d:sonar.login="tkoen"
SonarScanner for MSBuild 4.9
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
WARNING: The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis...
/home/travis/build/presque-fini/nez/Nez.Portable/Nez.csproj
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/SDL2.dll' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/SDL2.dll' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/soft_oal.dll' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/soft_oal.dll' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/libSDL2-2.0.so.0' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/libSDL2-2.0.so.0' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/libopenal.so.1' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/libopenal.so.1' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/libSDL2-2.0.0.dylib' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/libopenal.1.dylib' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/MonoGame.Framework.dll.config' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
The SONAR_SCANNER_HOME environment variable is not required and will be ignored.
Calling the SonarQube Scanner...
INFO: Scanner configuration file: /home/travis/build/presque-fini/presque-game/scanner/sonar-scanner-4.3.0.2102/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/travis/build/presque-fini/presque-game/.sonarqube/out/sonar-project.properties
INFO: SonarScanner 4.3.0.2102
INFO: Java 11.0.2 Oracle Corporation (64-bit)
INFO: Linux 4.15.0-1028-gcp amd64
INFO: User cache: /home/travis/.sonar/cache
INFO: Scanner configuration file: /home/travis/build/presque-fini/presque-game/scanner/sonar-scanner-4.3.0.2102/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/travis/build/presque-fini/presque-game/.sonarqube/out/sonar-project.properties
INFO: Analyzing on SonarCloud
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=706ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /home/travis/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=165ms
INFO: Load/download plugins (done) | time=22322ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=49ms
INFO: Project key: presque-fini_presque-game
INFO: Base dir: /home/travis/build/presque-fini
INFO: Working dir: /home/travis/build/presque-fini/presque-game/.sonarqube/out/.sonar
INFO: Load project settings for component key: 'presque-fini_presque-game'
INFO: Load project settings for component key: 'presque-fini_presque-game' (done) | time=227ms
INFO: Found an active CI vendor: 'TravisCI'
INFO: Load project branches
INFO: Load project branches (done) | time=136ms
INFO: Check ALM binding of project 'presque-fini_presque-game'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'presque-fini_presque-game' (done) | time=122ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=141ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=4ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=156ms
INFO: Load active rules
INFO: Load active rules (done) | time=3676ms
INFO: Organization key: presque-fini
INFO: Indexing files...
INFO: Project configuration:
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 33.193s
INFO: Final Memory: 7M/27M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: Not inside a Git work tree: /home/travis/build/presque-fini
ERROR:
The SonarQube Scanner did not complete successfully
13:29:46.773 Post-processing failed. Exit code: 1
The command "mono ./scanner/SonarScanner.MSBuild.exe end -d:sonar.login="token"" exited with 1.
系统配置
- CI:特拉维斯(您可以在此处浏览完整版本:https://travis-ci.com/github/presque-fini/presque-game/builds/172666297)
- OS: Ubuntu 16.04.6 LTS
- Git 2.21.0
- 使用的版本:
sonar-scanner-msbuild-4.9.0.17385-net46
- 扫描仪命令:
mono ./scanner/SonarScanner.MSBuild.exe end -d:sonar.login="token"
- 项目托管在 Github (https://github.com/presque-fini/presque-game)
有什么问题?
问题是因为当 Travis 克隆你的项目时,它会将它克隆到一个以 repo 名称命名的子目录中(presque-game
在你的例子中)。这将为您提供以下结构:
organization-name/repo-name
启动分析时,它默认在 organization-name
文件夹中启动,而不是在 repo-name
子文件夹中启动。因为 organization-name
不是 git 回购,Sonarcloud 失败。
我该如何解决?
解决这个问题,需要设置解析属性 sonar.projectBaseDir
:
-d:sonar.projectBaseDir="repo-name/"
这将为您提供完整的命令(路径是绝对路径,但我想相对路径也可以):
mono ./scanner/SonarScanner.MSBuild.exe begin -k:"presque-fini_presque-game" -o:"presque-fini" -d:sonar.login="token" -d:sonar.projectBaseDir="/home/travis/build/presque-fini/presque-game/"
参考文献:
- SonarCloud docs, Alternate analysis section:
If the files to be analyzed are not in the directory where the analysis starts from, use the sonar.projectBaseDir property to move analysis to a different directory.
- SonarQube 社区问题:SonarQube Scanner fails with “Not inside a git worktree” error
我在 C#
项目中使用 Travis CI 到 运行 SonarQube 扫描仪。我设法让扫描器工作了一次,但在下一次提交时没有明显原因失败(提交已更新 README.md
)。
我尝试清除构建缓存,但没有成功。我也读过其他编程语言(Java 主要)的问题,但到目前为止运气不好。
错误日志
具体错误为:
Not inside a Git work tree: /home/travis/build/presque-fini
完整的错误日志如下:
34.72s$ mono ./scanner/SonarScanner.MSBuild.exe end -d:sonar.login="tkoen"
SonarScanner for MSBuild 4.9
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
WARNING: The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis...
/home/travis/build/presque-fini/nez/Nez.Portable/Nez.csproj
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/SDL2.dll' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/SDL2.dll' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/soft_oal.dll' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/soft_oal.dll' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/libSDL2-2.0.so.0' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/libSDL2-2.0.so.0' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x86/libopenal.so.1' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/x64/libopenal.so.1' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/libSDL2-2.0.0.dylib' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/libopenal.1.dylib' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
WARNING: File '/usr/lib/mono/xbuild/MonoGame/v3.0/Assemblies/DesktopGL/MonoGame.Framework.dll.config' is not located under the root directory '/home/travis/build/presque-fini' and will not be analyzed.
The SONAR_SCANNER_HOME environment variable is not required and will be ignored.
Calling the SonarQube Scanner...
INFO: Scanner configuration file: /home/travis/build/presque-fini/presque-game/scanner/sonar-scanner-4.3.0.2102/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/travis/build/presque-fini/presque-game/.sonarqube/out/sonar-project.properties
INFO: SonarScanner 4.3.0.2102
INFO: Java 11.0.2 Oracle Corporation (64-bit)
INFO: Linux 4.15.0-1028-gcp amd64
INFO: User cache: /home/travis/.sonar/cache
INFO: Scanner configuration file: /home/travis/build/presque-fini/presque-game/scanner/sonar-scanner-4.3.0.2102/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/travis/build/presque-fini/presque-game/.sonarqube/out/sonar-project.properties
INFO: Analyzing on SonarCloud
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=706ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /home/travis/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=165ms
INFO: Load/download plugins (done) | time=22322ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=49ms
INFO: Project key: presque-fini_presque-game
INFO: Base dir: /home/travis/build/presque-fini
INFO: Working dir: /home/travis/build/presque-fini/presque-game/.sonarqube/out/.sonar
INFO: Load project settings for component key: 'presque-fini_presque-game'
INFO: Load project settings for component key: 'presque-fini_presque-game' (done) | time=227ms
INFO: Found an active CI vendor: 'TravisCI'
INFO: Load project branches
INFO: Load project branches (done) | time=136ms
INFO: Check ALM binding of project 'presque-fini_presque-game'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'presque-fini_presque-game' (done) | time=122ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=141ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=4ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=156ms
INFO: Load active rules
INFO: Load active rules (done) | time=3676ms
INFO: Organization key: presque-fini
INFO: Indexing files...
INFO: Project configuration:
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 33.193s
INFO: Final Memory: 7M/27M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: Not inside a Git work tree: /home/travis/build/presque-fini
ERROR:
The SonarQube Scanner did not complete successfully
13:29:46.773 Post-processing failed. Exit code: 1
The command "mono ./scanner/SonarScanner.MSBuild.exe end -d:sonar.login="token"" exited with 1.
系统配置
- CI:特拉维斯(您可以在此处浏览完整版本:https://travis-ci.com/github/presque-fini/presque-game/builds/172666297)
- OS: Ubuntu 16.04.6 LTS
- Git 2.21.0
- 使用的版本:
sonar-scanner-msbuild-4.9.0.17385-net46
- 扫描仪命令:
mono ./scanner/SonarScanner.MSBuild.exe end -d:sonar.login="token"
- 项目托管在 Github (https://github.com/presque-fini/presque-game)
有什么问题?
问题是因为当 Travis 克隆你的项目时,它会将它克隆到一个以 repo 名称命名的子目录中(presque-game
在你的例子中)。这将为您提供以下结构:
organization-name/repo-name
启动分析时,它默认在 organization-name
文件夹中启动,而不是在 repo-name
子文件夹中启动。因为 organization-name
不是 git 回购,Sonarcloud 失败。
我该如何解决?
解决这个问题,需要设置解析属性 sonar.projectBaseDir
:
-d:sonar.projectBaseDir="repo-name/"
这将为您提供完整的命令(路径是绝对路径,但我想相对路径也可以):
mono ./scanner/SonarScanner.MSBuild.exe begin -k:"presque-fini_presque-game" -o:"presque-fini" -d:sonar.login="token" -d:sonar.projectBaseDir="/home/travis/build/presque-fini/presque-game/"
参考文献:
- SonarCloud docs, Alternate analysis section:
If the files to be analyzed are not in the directory where the analysis starts from, use the sonar.projectBaseDir property to move analysis to a different directory.
- SonarQube 社区问题:SonarQube Scanner fails with “Not inside a git worktree” error