Analyze project with Bitbucket pipeline: Unable to connect to server

Must-share information (formatted with Markdown):

  • SonarQube 10.5, Scanner
  • SonarQube is deployed from zip
  • Analyze my project with Bitbucket pipeline
  • I checked SONAR_HOST_URL -no problem

Pipeline is failed:
Unable to connect to server. Please check if the server is running and if the address is correct. Url: '$SONAR_HOST_URL/api/server/version'. An error occured while querying the server version! Please check if the server is running and if the address is correct.

Hey there

Is this what the logs actually say? That would lead be to believe the environment variable isn’t being resolved to its actual value.

Can you share your full Bitbucket Pipelines YML here?

Hi Colin, thanks for the quick response. :slightly_smiling_face:
1.It is a snapshot from the pipeline runner:


2.My bitbucket-pipelines.yml

image: mcr.microsoft.com/dotnet/sdk:7.0

definitions:
  steps:
    - step: &build-step
        name: SonarQube analysis
        caches:
          - dotnetcore
          - sonar
        script:
          - apt-get update
          - apt-get install --yes --no-install-recommends openjdk-17-jre
          - dotnet tool install --global dotnet-sonarscanner
          - export PATH="$PATH:/root/.dotnet/tools"
          - dotnet sonarscanner begin /k:"myrepo_95080048-e76f-4144-bec5-e75f81f4b553" /d:"sonar.token=${SONAR_TOKEN}"  /d:"sonar.host.url=${SONAR_HOST_URL}"
          - dotnet build 
          - dotnet sonarscanner end /d:"sonar.token=${SONAR_TOKEN}"
  caches:
    sonar: ~/.sonar

pipelines:
  branches:
    '{master}':
      - step: *build-step

  pull-requests:
    '**':
      - step: *build-step

3.I have two questions about a sonarscanner installation:
Why is it that every time I see the message ``The tools directory ‘/root/.dotnet/tools’ is not currently in the PATH environment variable.'`?
Where is the sonarscanner installed if the pipeline is running in the Bitbucket cloud?

Everything looks in order here. Can you make sure you haven’t set SONAR_HOST_URL as being Secured? SONAR_TOKEN needs to be set that way, but not SONAR_HOST_URL. If this changes the error message, post an updated version.

I guess you would avoid that message if you switched these two commands

But you end up with the same result.

It might be interesting feedback for our analysis tutorial folks that this could kill some noise. I’ll pass it on.

/root/.dotnet/tools

/root/.dotnet/tools
In my computer?
Because I don’t see it in %UserProfile%.dotnet\tools folder

I turned off the Secured option.Same result:

I found information on your site about SonarScanner, which works with the SonarQube secure server.


But to be honest, I don’t know what to do about it because I don’t know where SonarScanner is running from (in case it is being used from the Bitbucket cloud pipeline).

The SonarScanner is running in Bitbucket Pipelines, probably on a hosted agent (hosted by Bitbucket) that doesn’t have access to your internal network or machine.

What this usually means is that you need a SonarQube server accessible over the public internet, or at least by the Bitbucket runners

Colin thanks for the explanation.
Please don’t close this topic yet because I need to find out some details about this …