Sonarqube v.4 TFS 任务 "Publish Analysis Result" 抛出错误 "Could not fetch metrics"

Sonarqube v.4 TFS task "Publish Analysis Result" throw error "Could not fetch metrics"

在 TFS 上,我无法 运行 任务 "Publish Analysis Result" 在 TFS 网页上发布 Quality Gate。其他任务 "Prepare analysis on SonarQube" 和 "Run Code Analysis" 运行 成功。

错误信息是:

[error][SQ] Could not fetch metrics

[error][SQ] Could not fetch task for ID 'FWK9NiOFibiMfA2L0BHo'

尽管出现了错误消息,但当我访问 url http://localhost:9000/api/ce/task?id=FWK9NiOFibiMfA2L0BHo 时,我收到了包含任务信息的 json 响应。

似乎是 SonarQube VSTS 扩展的问题:

The SonarQube extension uses basic authentication to communicate with the SonarQube API endpoint, and uses the token as username, and password as null. The npm package 'request' (at least latest version 2.83.0), does not allow null passwords and returns 'auth() received invalid user or password'.

To fix it, the password should be set to an empty string instead.

Until the VSTS plugin is fixed by SonarSource, you can workaround the issue by manually editing the extension on your VSTS build machine. The file to edit is: <build location>\_tasks\SonarQubePublish_291ed61f-1ee4-45d3-b1b0-bf822d9095ef.0.0\common\helpers\request.js

Add a new row after row 22:

options.auth.pass = "";

详情请参考这个类似的帖子:Unable to integrate SonarQube analysis results with VSTS Build Summary