You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps中无法将SonarCloud @1 CLI任务替换为@2

SonarCloudPrepare@2 替换@1后报错“Project not found”的解决方法

问题背景

原SonarCloudPrepare@1任务(带长UUID前缀的格式)运行完全正常,但替换为SonarCloudPrepare@2后,持续收到错误:

##[error]ERROR: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties,
the 'SONAR_TOKEN' environment variable, or contact the project administrator to check the permissions of the user the token belongs to

原@1正常配置:

- task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
  condition: succeeded()
  displayName: "Prepare analysis on SonarCloud"
  inputs:
    SonarCloud: "SonarCloud - Analysis"
    organization: "x-apps"
    scannerMode: CLI
    configMode: manual
    cliProjectKey: "x"
    cliProjectName: "x"
    extraProperties: |
     xxx

解决方法

@2版本简化了任务ID,但部分输入参数的名称和逻辑有调整,适配后的配置如下:

- task: SonarCloudPrepare@2
  condition: succeeded()
  displayName: "Prepare analysis on SonarCloud"
  inputs:
    sonarCloud: "SonarCloud - Analysis"
    organization: "x-apps"
    scannerMode: "CLI"
    projectKey: "x"
    projectName: "x"
    extraProperties: |
      xxx

关键调整点:

  • 任务ID直接使用SonarCloudPrepare@2,无需原@1的长UUID前缀
  • 参数名称修改:
    • 原SonarCloud改为小写开头的sonarCloud
    • 原cliProjectKey简化为projectKey
    • 原cliProjectName简化为projectName
  • 确保管道中SONAR_TOKEN环境变量有效,或者SonarCloud服务连接(即配置中的"SonarCloud - Analysis")已绑定正确的令牌

后续验证

  1. 保存修改后的配置,重新运行管道
  2. 若仍报错,检查SonarCloud后台:确认organization和projectKey与配置完全一致,且令牌所属用户拥有该项目的分析权限

内容的提问来源于stack exchange,提问作者pantheon12

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 08:57:14