【问题标题】:Dotnet scanner error on Gitlab pipeline, how to resolve?Gitlab管道上的Dotnet扫描仪错误,如何解决?
【发布时间】:2022-11-09 06:11:57
【问题描述】:

我在 ubuntu 20.04 机器上通过带有 docker 的图像安装了 sonarqube。

我正在运行 gitlab 并使用管道执行声纳扫描。对于 python 和 javascript 存储库,这工作得很好,但是我有多个要分析的 c# 项目。

以下脚本在 gitlab-ci.yml 文件中使用:

sonarqube-check:
  stage: sonarqube-check
  image: mcr.microsoft.com/dotnet/core/sdk:latest
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
      - "sudo apt-get update"
      - "sudo apt-get install --yes openjdk-11-jre"
      - "sudo add-apt-repository universe"
      - "sudo apt-get install apt-transport-https"
      - "sudo dotnet tool update --global dotnet-sonarscanner"
      - "export PATH=\"$PATH:/root/.dotnet/tools\""
      - "echo $PATH"
      - "sudo dotnet tool list -g"
      - "sudo dotnet sonarscanner begin /k:\"machtrans_nanders-stand-up_secretkey\" /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "
      - "sudo dotnet build"
      - "sudo dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
  allow_failure: true
  only:
    - chore/implement-sonarqube-check

我已经在 gitlab runner 机器上手动安装了 net-sdk-6.0,它就像这样工作得很好。

当我运行它时,我收到以下错误并尝试了很多东西,但不知道如何解决它,我希望社区中的一个可以帮助我:

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/root/.dotnet/tools
$ sudo dotnet tool list -g
Package Id               Version      Commands           
---------------------------------------------------------
dotnet-sonarscanner      5.5.3        dotnet-sonarscanner
$ sudo dotnet sonarscanner begin /k:"machtrans_nanders-stand-1313216854315" /d:sonar.login="$SONAR_TOKEN" /d:"sonar.host.url=$SONAR_HOST_URL"
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET program, but dotnet-sonarscanner does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

【问题讨论】:

    标签: sonarqube gitlab-ci sonarscanner gitlab-runner


    【解决方案1】:

    确保路径 /root/.dotnet/tools 存在。我的猜测是,当您将它与sudo dotnet tool update --global dotnet-sonarscanner 和下一行一起使用时,它还不存在,所以当您执行dotnet sonarscanner begin 时,它在/root/.dotnet/tools 中找不到工具,因为路径在您的 PATH 中不存在。

    【讨论】:

      猜你喜欢
      • 2019-06-27
      • 1970-01-01
      • 2015-10-02
      • 2018-08-01
      • 2022-07-19
      • 2018-12-17
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多