【问题标题】:Teamcity CI Pipeline cannot run installed dotnet tool (sonarscanner)Teamcity CI Pipeline 无法运行已安装的 dotnet 工具 (sonarscanner)
【发布时间】:2021-08-09 18:14:30
【问题描述】:

我在 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 的问题,但 TeamCity 没有这些 YML 配置文件,我完全不知道如何应用 use dotnet 任务也没有必要,因为我只是想运行一个脚本。

【问题讨论】:

    标签: c# .net-core teamcity


    【解决方案1】:

    我认为你的 $executionPath 不在 PATH 环境变量中,所以找不到它。

    您应该能够在没有 dotnet sonarscanner 的情况下运行该命令,但使用 $executionPath\dotnet-sonarscanner.exe

    检查本地工具标题下的here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 2021-07-20
      • 2023-03-03
      • 1970-01-01
      • 2022-07-06
      • 2019-01-29
      相关资源
      最近更新 更多