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")已绑定正确的令牌
后续验证
- 保存修改后的配置,重新运行管道
- 若仍报错,检查SonarCloud后台:确认
organization和projectKey与配置完全一致,且令牌所属用户拥有该项目的分析权限
内容的提问来源于stack exchange,提问作者pantheon12
相关产品推荐
相关产品推荐

