##[error][SQ] API GET '/api/server/version' failed, error was: {"code":"ENOENT","errno":"ENOENT","syscall":"getaddrinfo","hostname":"localhost","host":"localhost","port":"9000"}

Hi everyone,

I have a problem when I try to use SonarScanner with Azure DevOps pipeline.

I have 4.18 version of sonarscanner and 8.7 version of SonarQube.

I create a pipeline with the next tasks:

  • Prepare analysis on SonarQube

  • Build sln

  • Run Code Analysis

  • Publish Quality Gate Results

All them are configured equal as the documentation said.

When I queue pipeline, I get the next error in “Prepare analysis on SonarQube":

##[section]Starting: Prepare analysis on SonarQube
==============================================================================
Task : Prepare Analysis Configuration
Description : Prepare SonarQube analysis configuration
Version : 4.18.0
Author : sonarsource
Help : Version: 4.18.0. More Information
==============================================================================
##[error][SQ] API GET ‘/api/server/version’ failed, error was: {“code”:“ENOENT”,“errno”:“ENOENT”,“syscall”:“getaddrinfo”,“hostname”:“localhost”,“host”:“localhost”,“port”:“9000”}
##[section]Finishing: Prepare analysis on SonarQube

Can anyone help me with this error?

Thanks in advance.

Hey there.

Is SonarQube running on the same machine as your Azure DevOps agent? That’s the only way that using localhost would make sense :wink:

Hi @Colin,

Yes, SonarQube is running on the same machine as Azure DevOps agent, Azure DevOps Server and SQL Server database.

Interesting (and not particularly recommended).

Let’s take the SonarQube tasks out of the piccture. What happens if you try and just execute a curl command (or equivalent) to http://localhost:9000/api/server/version while on the agent?

I get the SonarQube version:
image

Hi @Colin,

I have found a problem that may be related to this one.

When I try to use the api to get measures of a project (http://localhost:9000/api/measures/component?component=PROJECT&metricKeys=vulnerabilities,bugs) and I don’t be login on SonarQube web, I get a 401 error (Unauthorized).

Maybe I didn’t configure something in SonarQube in the right way.

I configured SonarQube as it says in SonarQube Docs (SonarQube Documentation | SonarQube Docs).

Thanks in advance.

I would really start with double-checking the service connection you configured in Azure DevOps. Is the URL correct (http://localhost:9000 by the sounds of it) and a valid token with Execute Analysis permissions provided?

Hi @Colin,
I verified that the service connection I configured in Azure DevOps is correct (url, project and token).

When you say:

a valid token with Execute Analysis permissions provided

What do you refer?
Because when I create a token in SonarQube, I cannot specific permissions…