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

SonarCloud扫描成功后质量门检查失败:日志文件缺失求助

解决Bitbucket Pipelines中SonarCloud质量门找不到扫描日志的问题

你遇到的问题核心是sonarsource/sonarcloud-quality-gate管道无法定位到sonarcloud-scan生成的日志文件,尽管扫描步骤本身执行成功了。这种情况大多是因为旧版本管道之间的默认路径不兼容导致的,下面给你几个可行的解决方案:

1. 优先升级SonarCloud管道到最新版本

你当前使用的sonarcloud-scan:0.1.5和sonarcloud-quality-gate:0.1.1都是比较老旧的版本,官方后续迭代已经修复了这类路径匹配的bug。直接升级到最新稳定版是最省心的解决方式:

修改你的bitbucket.yml中的管道版本:

- pipe: sonarsource/sonarcloud-scan:2.2.0 # 可替换为当前最新稳定版
  variables:
    SONAR_TOKEN: ${SONAR_TOKEN}
    EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**.test.jsx" -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info'
- pipe: sonarsource/sonarcloud-quality-gate:1.0.0 # 可替换为当前最新稳定版
  variables:
    SONAR_TOKEN: ${SONAR_TOKEN}

2. 手动指定日志文件路径(适用于暂不想升级的场景)

如果暂时不想升级管道,可以手动统一两个管道的日志文件路径,让质量门管道明确知道去哪里读取扫描日志:

修改后的步骤配置如下:

- pipe: sonarsource/sonarcloud-scan:0.1.5
  variables:
    SONAR_TOKEN: ${SONAR_TOKEN}
    EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**.test.jsx" -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info'
    LOG_FILE: '/opt/atlassian/pipelines/agent/build/sonarcloud-scan.log' # 手动指定扫描日志输出路径
- pipe: sonarsource/sonarcloud-quality-gate:0.1.1
  variables:
    SONAR_TOKEN: ${SONAR_TOKEN}
    SCAN_REPORT_PATH: '/opt/atlassian/pipelines/agent/build/sonarcloud-scan.log' # 告诉质量门管道日志位置

3. 显式指定工作目录(兜底排查方案)

虽然你的两个管道在同一个step下,默认应该共享工作目录,但旧版本管道可能存在工作目录漂移的问题。可以给两个管道都显式指定工作目录:

- pipe: sonarsource/sonarcloud-scan:0.1.5
  variables:
    SONAR_TOKEN: ${SONAR_TOKEN}
    EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**.test.jsx" -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info'
    WORKING_DIRECTORY: '/opt/atlassian/pipelines/agent/build'
- pipe: sonarsource/sonarcloud-quality-gate:0.1.1
  variables:
    SONAR_TOKEN: ${SONAR_TOKEN}
    WORKING_DIRECTORY: '/opt/atlassian/pipelines/agent/build'

优先推荐第一种升级方案,不仅能解决当前的日志路径问题,还能获得官方后续的bug修复和功能优化,避免其他潜在的兼容性问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 09:04:02