c# - Teamcity CI Pipeline 无法运行已安装的 dotnet 工具 (sonarscanner)
问题描述
我在 Teamcity (OnPremise) 中有一个 CI 构建管道,我想从 SonarQube 运行 sonarscanner 进行代码分析。我尝试了很多,包括 SonarQube Runner 的 Teamcity 插件。但它并没有真正起作用,所以我最终得到了以下脚本。
它安装了 dotnet 工具“sonarscanner”和“JetBrains.dotCover.GlobalTool”。当我在终端本地运行脚本时,一切正常。但是当我在 TeamCity 的 Build-Process 中运行脚本时,它会在尝试执行时崩溃dotnet.exe sonarscanner begin [..]
Could not execute because the specified command or file was not found.
16:01:24
Possible reasons for this include:
16:01:24
* You misspelled a built-in dotnet command.
16:01:24
* You intended to execute a .NET program, but dotnet-sonarscanner does not exist.
16:01:24
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
我已经从脚本中删除了一些其他不相关的东西。
[..]
dotnet tool install dotnet-sonarscanner --tool-path $executionPath
dotnet tool install JetBrains.dotCover.GlobalTool --tool-path $executionPath
write-host "tool installation finished"
write-host "Starting restore... "
dotnet.exe restore $absoluteSolutionPath --interactive --force
write-host "Restore done"
write-host "Init Sonar Scanner"
dotnet.exe sonarscanner begin /k:"ProjectKey" /d:sonar.host.url="https://ValidDomain" /d:sonar.login="ValidLoginKey" /d:sonar.cs.dotcover.reportsPaths=".\dotCover.Output.html"
write-Host "Sonar Scanner initialized"
write-host "Start Build Task"
dotnet.exe build $absoluteSolutionPath
write-host "Build Task completed"
[..]
安装后输出说
Tool 'dotnet-sonarscanner' (version '5.2.1') was successfully installed.
所以安装成功,但执行不成功?!我还在构建服务器上手动执行了脚本,它工作正常。
我在这里缺少的 TeamCity 脚本执行中有什么特别之处吗?
我还看到了Azure DevOps - cannot run installed dotnet tool but TeamCity 没有这些 YML 配置文件的问题,我完全不知道如何应用use dotnet Task 也不知道为什么它应该是必要的,因为我只想运行一个脚本.
解决方案
我认为您的 $executionPath 不在 PATH 环境变量中,因此找不到它。
您应该能够在没有 dotnet sonarscanner 的情况下运行该命令,但使用 $executionPath\dotnet-sonarscanner.exe
在“本地工具”标题下查看此处。
推荐阅读
- node.js - 使用 NodeJS 的 MongoDB 集合
- jquery - jquery中的函数在函数调用中定义时返回未定义
- angular - Angular 6 路由 ngOnInit 未调用
- xml - dotnet core REST API 发布数据无法从请求中的列表中读取 XML
- javascript - 在 javascript 中访问我的 json 响应的元素
- windows - 如何使用十六进制编辑器删除突出显示的代码行?
- hadoop - 卡在 ambari 2.6.2 中的应用时间线服务器安装
- java - Android Studio Activity 启动延迟
- security - 被浏览器拒绝的二级域的通配符 SSL/TLS 证书
- c# - 无法通过c#将数据从ms访问传到mysql