Error Integration Bitbucket Pipeline and SonarCloud

  • ALM used Bitbucket Cloud

  • CI system used Bitbucket Cloud

  • Languages of the repository: Angular (Other (for JS, TS, Go, Python, PHP, …))

  • Error observed
    ERROR: Error during SonarScanner execution

ERROR: Not authorized. Please check the property sonar.login or SONAR_TOKEN env variable

  • Steps to reproduce
    SONAR_TOKEN already generated and added to my ENV_VAR

image: ‘node:12.22’
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly

definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:

  • step: &build-test-sonarcloud
    name: Build, test and analyze on SonarCloud
    caches:
    - sonar
    script:
    - pipe: sonarsource/sonarcloud-scan:1.2.1
    variables:
    EXTRA_ARGS: ‘-Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${SONAR_TOKEN}’

  • step: &check-quality-gate-sonarcloud
    name: Check the Quality Gate on SonarCloud
    script:
    - pipe: sonarsource/sonarcloud-quality-gate:0.1.4

pipelines:
branches

* Potential workaround
No idea.

Hey there.

  • Is the project already created in SonarCloud, and bound to the Bitbucket Cloud repo?
  • You should not need to add either of these arguments to your pipeline.

@Colin the project is bounded from bitbucket.
Current yaml

      script:
        - pipe: sonarsource/sonarcloud-scan:1.2.1
          variables:
             SONAR_TOKEN: ${SONAR_CLOUD_TOKEN}
             SONAR_SCANNER_OPTS: -Xmx512m
             DEBUG: "true"

Pipeline Build Repo
Pipeline Build SonarScan
Pipeline Deploy Repo
Pipeline Deploy SonarGate
But without the host.url said the same message “ERROR: SONARQUBE SERVER [HTTP://LOCALHOST:9000] CAN NOT BE REACHED”
What am I doing wrong?

@Colin But when i declare like this.

definitions:
 caches:
   sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
 steps:
 - step: &build-test-sonarcloud
     name: Build, test and analyze on SonarCloud
     caches:
       - sonar
     script:
       - pipe: sonarsource/sonarcloud-scan:1.2.1
         variables:
            SONAR_TOKEN: $SONAR_CLOUD_TOKEN
            SONAR_SCANNER_OPTS: -Xmx512m
            DEBUG: "true"
            EXTRA_ARGS: '-Dsonar.host.url=https://sonarcloud.io -Dsonar.login=SONAR_TOKEN'   
 - step: &check-quality-gate-sonarcloud
     name: Check the Quality Gate on SonarCloud
     script:
       - pipe: sonarsource/sonarcloud-quality-gate:0.1.4

 

the cli :

Caused by: Not authorized. Please check the property sonar.login or SONAR_TOKEN env variable

Is it possible you have a sonar-project.properties file somewhere in your repository that’s pointing to http://localhost:9000?

@Colin there is not sonar-project.propeties file created, or do we need to manually create it ? i was guessing that by using sonar cloud it’s going to auto bind

Hey there.

Typically, in Bitbucket Pipelines, the default host should be https://sonarcloud.io unless overriden somewhere. This relies on the presence of the BITBUCKET_BUILD_NUMBER environment variable. Is that environment variable available during your build?

In any case, even if you still need to manually set sonar.host.url, it’s not the end of the world. I would encourage leaving out -Dsonar.login and relying on having SONAR_TOKEN configured)

  • You may want to try using the latest version of the pipe, 1.4.0.
  • Can you confirm how/where you’re setting SONAR_TOKEN? A screenshot would be helpful.

During the build step this appear:

 --env=BITBUCKET_BUILD_NUMBER="$BITBUCKET_BUILD_NUMBER" \

So I be guessing that is correct?
Answering the second question:
How to change pipe version?
and the log output also these:

   --env=EXTRA_ARGS="-Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN" \
   --env=SONAR_SCANNER_OPTS="-Xmx512m" \
   --env=SONAR_TOKEN="$SONAR_CLOUD_TOKEN" \
   --add-host="host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL" \
   sonarsource/sonarcloud-scan:1.2.1

The VAR is SONAR_CLOUD_TOKEN is defined on Project>Repository Settings >Repository Variables

PD: I already changed SONAR_TOKEN → SONAR_CLOUD_TOKEN just to believe there was a problem with that, but unfortunately, it doesn’t work either way

@Colin any suggestion?

Hey @ARCQ

As noted before, I really think you need to simplify your configuration (and make sure it’s up to date).

  • Change v1.2.1 of the sonarsource/sonarcloud-scan to v1.4.0 in your YAML file.

     - pipe: sonarsource/sonarcloud-scan:1.2.1
    
  • Remove sonar.login from your EXTRA_ARGS

  • Remove SONAR_TOKEN from the declared variables, relying on this existing only as a repository secret (which should be named, exactly, SONAR_TOKEN)

  • Ensure the user you have generated the SonarCloud token for has Execute Analysis rights on the project.

Finally, back to this point:

I would double check that this log line appears in your analysis attempts (and shows NONE)

INFO: Project root configuration file: NONE

Amazing! :clap:
Currently is scanning! :sweat_smile:
But now get stuck in…

ERROR: eslint-bridge Node.js process is unresponsive. This is most likely caused by process running out of memory. Consider setting sonar.javascript.node.maxspace to higher value (e.g. 4096).

Well… we’re further along. :slight_smile:

Make sure you remove SONAR_SCANNER_OPTS while you’re at it (you may be limiting the amount of memory available to the scanner), and if you can try increasing the amount of memory available to the docker container.

Current yaml definition that’s “out of memory”.
13:06:42.741 ERROR: eslint-bridge Node.js process is unresponsive. This is most likely caused by process running out of memory. Consider setting sonar.javascript.node.maxspace to higher value (e.g. 4096).

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  services:
    docker:
      memory: 1024  #increasing docker service memory
  steps:
  - step: &build-test-sonarcloud
      name: Build, test and analyze on SonarCloud
      size: 2x
      caches:
        - sonar
      script:
        - pipe: sonarsource/sonarcloud-scan:1.4.0
          variables:
             DEBUG: "true"
             EXTRA_ARGS: '-Dsonar.host.url=https://sonarcloud.io'   
  - step: &check-quality-gate-sonarcloud
      name: Check the Quality Gate on SonarCloud
      script:
        - pipe: sonarsource/sonarcloud-quality-gate:0.1.4
	

How does increasing this affect the behavior?