3

I am using Prepare, Run and Publish analysis tasks in VSTS to run the SonarQube analysis and publish the results to build summary. First two steps execute successfully but the 'Publish Analysis' task fails because it is not able to fetch the task for analysis ID. I get the following error message:

Could not fetch task for ID 'AWE9-wu8-fbfJflhFQ3-'

VSTS Publish Analysis Task Log:

2018-01-28T18:15:28.1037139Z ##[debug][SQ] Waiting for task 'AWE9-wu8-fbfJflhFQ3-' to complete.
2018-01-28T18:15:28.1037139Z ##[debug][SQ] API GET: '/api/ce/task' with query "{"id":"AWE9-wu8-fbfJflhFQ3-"}"
2018-01-28T18:15:28.1047138Z ##[debug][SQ] Publish task error: [SQ] Could not fetch task for ID 'AWE9-wu8-fbfJflhFQ3-'
2018-01-28T18:15:28.1047138Z ##[debug]task result: Failed
2018-01-28T18:15:28.1047138Z ##[error][SQ] Could not fetch task for ID 'AWE9-wu8-fbfJflhFQ3-'
2018-01-28T18:15:28.1047138Z ##[debug]Processed: ##vso[task.issue type=error;][SQ] Could not fetch task for ID 'AWE9-wu8-fbfJflhFQ3-'
2018-01-28T18:15:28.1047138Z ##[debug]Processed: ##vso[task.complete result=Failed;][SQ] Could not fetch task for ID 'AWE9-wu8-fbfJflhFQ3-'
2018-01-28T18:15:28.3907147Z ##[section]Finishing: Publish Analysis Result
  • Is this the first time you see this error? What did you change? Post also the SonarQube version you use. – Jeroen Heier Jan 29 '18 at 05:03
  • HI Jeroen. I was using SonarQube Scanner CLI earlier but now that it is deprecated i tried to add these tasks to VSTS CI pipeline. I am using SonarQube 5.6.6 version – vignesh srinivasan Jan 29 '18 at 05:53
  • What happen if you open /api/ce/task?id=AWE9-wu8-fbfJflhFQ3- in your web browser? Can you also look at your SonarQube server logs (in particular access.log) to see if the request is correctly received, and what is the response code. – Julien H. - SonarSource Team Jan 29 '18 at 08:46
  • Seems the task 'AWE9-wu8-fbfJflhFQ3-' is completed, refer to the logs of `Prepare` and `Run` steps to check if there are any unexpected issues there. – Andy Li-MSFT Jan 29 '18 at 09:31
  • @JulienH.-SonarSourceTeam Hi Julien. I am able to see the response when I hit the URL in the browser. I checked the log and it returns http 200. below is the log: 52.175.245.235 - - [29/Jan/2018:18:04:26 +0000] "GET /api/metrics/search?f=name&ps=500 HTTP/1.1" 200 11700 "-" "-" 52.175.245.235 - - [29/Jan/2018:18:04:26 +0000] "GET /api/ce/task?id=AWFDF2_V5a2xaxKZBC2l HTTP/1.1" 200 357 "-" "-" – vignesh srinivasan Jan 29 '18 at 18:34

3 Answers3

2

I was seeing the exact same problem as Vignesh. Running SonarQube 6.7.1 and latest version of VSTS SonarQube extension.

I found out what the problem was; it's in the SonarQube VSTS Extensions (Prepare, Analyse & Publish).

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\4.0.0\common\helpers\request.js

Add a new row after row 22:

options.auth.pass = "";

The endresult should be something like:

var options = {
    auth: endpoint.auth
};
if (query) {
    options.qs = query;
    options.useQuerystring = true;
}
options.auth.pass = "";
request.get(__assign({ method: 'GET', baseUrl: endpoint.url, uri: path, json: true }, options), function (error, response, body) {

I give no guarantees, but this worked for me.

  • Am looking into this. Would like to know something (since this doesn't seem systematic, e.g. can't reproduce with VSTS + [SonarCloud](https://sonarcloud.io): is _Force Authentication_ turned on in your SonarQube settings ? (security section) – Nicolas B. Feb 01 '18 at 17:12
  • No, it was not turned on. Still had the problem. – Henrik Klinkmann Feb 02 '18 at 18:01
  • Understood, that was a wild guess and was in fact a wrong guess. Actual problem (and related solution) is described in @Julien H. answer. – Nicolas B. Feb 05 '18 at 10:37
1

We are using the TFS extension in version 4.0.1 and the failure is still there.

2018-02-07T10:34:41.7065486Z ##[debug][SQ] Waiting for task 'AWFv1Mcg5obW39zt_5IE' to complete.
2018-02-07T10:34:41.7065486Z ##[debug][SQ] API GET: '/api/ce/task' with query "{"id":"AWFv1Mcdgfdg39zt_5IE"}"
2018-02-07T10:34:41.7690509Z ##[debug][SQ] Publish task error: [SQ] Could not fetch task for ID 'AWFv1Mcdgfdg39zt_5IE'
2018-02-07T10:34:41.7690509Z ##[debug]task result: Failed
2018-02-07T10:34:41.7690509Z ##[error][SQ] Could not fetch task for ID 'AWFv1Mcdgfdg39zt_5IE'
2018-02-07T10:34:41.7690509Z ##[debug]Processed: ##vso[task.issue type=error;][SQ] Could not fetch task for ID 'AWFv1Mcdgfdg39zt_5IE'
2018-02-07T10:34:41.7690509Z ##[debug]Processed: ##vso[task.complete result=Failed;][SQ] Could not fetch task for ID 'AWFv1Mcdgfdg39zt_5IE'

See screenshot here

KretaPan
  • 31
  • 3
  • @Julien H. - SonarSource Team The Problem is not solved in our case. See my post from Feb 7 at 12:1 – KretaPan Feb 20 '18 at 10:47
0

This was indeed caused by passing a null password to the request library. A fix have been deployed (version 4.0.1 of the SonarQube extension, version 4.0.1 of the publish task). See https://jira.sonarsource.com/browse/VSTS-134